PhoneGap: modify config.xml to add properties to Info.plist ion iOS

你离开我真会死。 提交于 2019-11-30 20:20:39

I achieve this using a build hook for iOS. So, in config.xml I'd put something like:

<hook type="before_build" src="../scripts/ios_before_build.sh" />

Inside the:

 <platform name="ios">

element in config.xml

Then I'd create a file called ../scripts/ios_before_build.sh, make sure it has execute permissions (chmod 755 ../scripts/ios_before_build.sh) then set the script to use PlistBuddy to make required changes to the .plist file.

For example here I am turning off iOS 9 requirement for SSL secured backend URLs as the API for the app I was developing doesn't use https:

val=$(/usr/libexec/plistbuddy -c "add NSAppTransportSecurity:NSAllowsArbitraryLoads bool true" platforms/ios/AppName/AppName-Info.plist 2>/dev/null)

I'm suppressing the return code of plistbuddy as it will fail if the item exists already. Here I'm adding a dict and setting a boolean value but you can do a variety of other stuff as per PlistBuddy documentation.

Then when you do:

cordova build ios

The script will be run, alter your plist then the cordova build will continue.

I find this cleaner as I don't like to have the platforms or plugins folder checked into version control on my Cordova projects.

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