Created
September 26, 2011 11:24
-
-
Save keijiro/1242050 to your computer and use it in GitHub Desktop.
PostprocessBuildPlayer for Unity iOS: modifies Info.plist to use Facebook URL-scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, os.path | |
install_path = sys.argv[1] | |
target_platform = sys.argv[2] | |
if target_platform != "iPhone": sys.exit() | |
info_plist_path = os.path.join(install_path, 'Info.plist') | |
file = open(info_plist_path, 'r') | |
plist = file.read() | |
file.close() | |
elements_to_add = ''' | |
<key>CFBundleURLTypes</key> | |
<array> | |
<dict> | |
<key>CFBundleURLSchemes</key> | |
<array> | |
<string>fbXXXXXXXXXXXXXXX</string> | |
</array> | |
</dict> | |
</array> | |
<key>CFBundleLocalizations</key> | |
<array> | |
<string>en</string> | |
<string>ja</string> | |
</array> | |
''' | |
plist = plist.replace('<key>', elements_to_add + '<key>', 1) | |
file = open(info_plist_path, 'w') | |
file.write(plist) | |
file.close() |
@brunogama Thanks for your hint.
If many url schemes you want to add, can do as following:
def addUrlScheme(plist, sns, sns_short, id):
scheme_value = sns_short+id
new_dict = {'CFBundleTypeRole': 'Editor', 'CFBundleURLName': sns, 'CFBundleURLSchemes': [scheme_value]}
if "CFBundleURLTypes" in plist:
plist["CFBundleURLTypes"].append(new_dict.copy())
else:
plist["CFBundleURLTypes"] = [new_dict]
e.g.
addUrlScheme(pl, 'facebook', 'fb', fb_appid)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've done something similar but I used the plistLib module: