简体   繁体   中英

Using a javascript file to store an API key needed in an Xcode project

I recently made an iOS app I programmed with Swift public on github, and realized that my API key is in the project, and now visible to anyone. I used this link to solve my problem, and it says to create a config.js file that contains my API Keys in it, and then access those and store them in variables in the file that needs the key, but it seems that the example is for an HTML file, and I do not know how to do step 4 for my situation (the API key is needed in my app's AppDelegate.swift file). Eventually the config.js file will be placed in a .gitignore file.

If anyone has a better way for me to hide my API key from github without completely removing the AppDelegate.swift file from github, I am open to other suggestions.

I did what Chris G commented and created a JSON file, which I opened and parsed in my App Delegate. It worked.

FYI, don't forget to go to do Project > Build Phases > Copy Bundle Resources > + in order to add the JSON file to your bundle so you can access it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM