Using Microsoft App Center environment variables in iOS

ぃ、小莉子 提交于 2021-02-10 06:15:00

问题


I want to open source my iOS app but still be able to build it using a CI system like Microsoft App Center. My app uses private API keys that I want to hide from my open source repository.

Fortunately App Center offers the environment variables feature, which are intended to use at build time. Their documentation says they can be used like this in bash:

$ENVIRONMENT_VARIABLE

So, say I have an environment variable called GoogleAPIKey configured in App Center, can I retrieve it like this ProcessInfo.processInfo.environment["GoogleAPIKey"] ?? "" in my app? If yes, how do I test the app on my device if only App Center has the key (I don't want to put it in my code since that would mean it would be public (do I need to use gitignore)?


回答1:


I don't think you can read environment variables inside the app. You can access environment variables in a custom bash scripts only. However I think you can modify app project files inside the build script. So you may try something like this:

  1. Add a special text file to xcode project and commit it to your repository.
  2. Add environment variable with GoogleAPIKey value
  3. Write GoogleAPIKey value to the text file inside the build script.
  4. Read GoogleAPIKey value from text file with your Swift code


来源:https://stackoverflow.com/questions/54266481/using-microsoft-app-center-environment-variables-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!