YShin
YShin

Reputation: 565

XCode: How to separate confidential information from source code?

I'm a beginner in iOS development, and trying to build a practice app using Facebook Graph API.

When I integrate with the Facebook API, it requires me to store App ID into Info.plist file of the project.(https://developers.facebook.com/docs/ios/getting-started#configure)

Although Facebook's app id is not super confidential, I want to open source my repository on GitHub, and having to upload App ID along with source code bothered me.

I could add such file to .gitignore, or make sure I delete confidential information whenever I upload it to GitHub, but they are apparently error prone, and not elegant at all.

Coming form the Java background, I used to store database passwords and other secretive information as system Environment Variables, or stored them in the build tool's setting file such as Maven's settings.xml, so that they are maintained separate from the source code.

Are there known best practices to decouple confidential information from repository in iOS development?

Thank you.

Upvotes: 3

Views: 219

Answers (1)

vladof81
vladof81

Reputation: 26499

What about this scenario:

  1. Create a file MyId.txt on your Mac (home directory or a directory that can be shared, for example ~/FacebookConfidential/) to store FacebookAppId.

  2. Add Run Script in your Xcode project Build Phases, read MyId.txt file content and set it to info plist using plistbuddy. The purpose is to update information property list so that Facebook SDK can get the Id at run time.

    INFO_PLIST="info.plist"
    FACEBOOK_ID=$(<~/FacebookConfidential/MyId.txt)
    if [ -n ${FACEBOOK_ID} ]; then
        /usr/libexec/PlistBuddy -c "Set :FacebookAppID ${FACEBOOK_ID}" ${INFO_PLIST}
    fi
    
  3. Use git pre-commit hook to clean FacebookAppId in info plist or change it a stub value, which make sure FacebookAppId is not committed to repository. You may also want to invoke plistbuddy in the hook.

  4. A collaborator need to do step 1 and create ~/FacebookConfidential/MyId.txt on his system.

This way, the FacebookAppId is saved on your system, the only thing to share is the path. Hope this shed light.

Upvotes: 4

Related Questions