Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exclude a secret key from an open-sourced Xcode project?

Tags:

xcode

ios

I am developing an iPhone app that uses the Facebook SDK to connect with Facebook. The SDK requires that my code set an app ID when calling code in the SDK (the app ID is registered with Facebook). I would like to open-source this project, but obviously I don't want my app ID to be used by others. How can I set up the project so that I can build it using my app ID, but other people could also build the project using their own?

like image 217
mipadi Avatar asked Oct 06 '22 11:10

mipadi


1 Answers

Assuming that you're adding your AppID and Secret in your app's plist, you could modify your build scheme for the Release build and add a "Post Build Command" that could run a script to do the following:

echo -n ${TARGET_BUILD_DIR}/${INFOPLIST_PATH} | xargs -0 /usr/libexec/PlistBuddy -c "Set :<Your Facebook App ID Key> YOUR_APP_ID_HERE"
echo -n ${TARGET_BUILD_DIR}/${INFOPLIST_PATH} | xargs -0 /usr/libexec/PlistBuddy -c "Set :<Your Facebook Secret Key> YOUR_APP_SECRET_HERE"

That would change the value of those plist entries to some generic value.

Here's a reference to what I'm talking about. Feel free to adjust accordingly.

like image 132
Simon Germain Avatar answered Oct 10 '22 03:10

Simon Germain