[英]PhoneGap: modify config.xml to add properties to Info.plist ion iOS
For my application, I need to add some settings to the Info.plist file for iOS. 对于我的应用程序,我需要为iOS的Info.plist文件添加一些设置。 I thought the best way to do this, would be to add these settings to my config.xml file (I'm using PhoneGap).
我认为最好的方法是将这些设置添加到我的config.xml文件中(我正在使用PhoneGap)。 When I add the following to the config.xml file and run
当我将以下内容添加到config.xml文件并运行时
cordova build ios
or 要么
cordova update platform ios
Nothing is added to my Info.plist file, and I absolutely have no idea why that is. 我的Info.plist文件中没有添加任何内容,我完全不知道为什么会这样。 The build show 'success', so I don't think there's a syntax error.
构建显示“成功”,所以我认为没有语法错误。
I've tried: 我试过了:
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<config-file target="*-Info.plist" parent="NSAppTransportSecurity">
<array>
<dict>
<key>NSExceptionDomains</key>
<array>
<dict>
<key>s3.amazonaws.com</key>
<array>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow insecure HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</array>
</dict>
</array>
</dict>
</array>
</config-file>
</platform>
And 和
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<config-file target="*-Info.plist" parent="NSAppTransportSecurity">
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>s3.amazonaws.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow insecure HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
</config-file>
</platform>
And 和
<gap:config-file platform="ios" parent="NSAppTransportSecurity">
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>s3.amazonaws.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow insecure HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
</gap:config-file>
And 和
<gap:config-file platform="ios" parent="NSAppTransportSecurity">
<array>
<dict>
<key>NSExceptionDomains</key>
<array>
<dict>
<key>s3.amazonaws.com</key>
<array>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow insecure HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</array>
</dict>
</array>
</dict>
</array>
</gap:config-file>
But nothing is added to the Info.plist file. 但是没有任何内容添加到Info.plist文件中。 What am I doing wrong here?
我在这做错了什么?
I achieve this using a build hook for iOS. 我使用iOS的构建钩子来实现这一点。 So, in config.xml I'd put something like:
所以,在config.xml中我会添加如下内容:
<hook type="before_build" src="../scripts/ios_before_build.sh" />
Inside the: 在 - 的里面:
<platform name="ios">
element in config.xml 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. 然后我创建一个名为../scripts/ios_before_build.sh的文件,确保它具有执行权限(chmod 755 ../scripts/ios_before_build.sh)然后将脚本设置为使用PlistBuddy对.plist进行必要的更改文件。
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: 例如,我在关闭SSL安全后端URL的iOS 9要求,因为我正在开发的应用程序的API不使用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. 我正在抑制plistbuddy的返回代码,因为如果项目已经存在,它将失败。 Here I'm adding a dict and setting a boolean value but you can do a variety of other stuff as per PlistBuddy documentation .
这里我添加了一个dict并设置了一个布尔值,但你可以根据PlistBuddy文档做各种其他的东西。
Then when you do: 然后你做的时候:
cordova build ios
The script will be run, alter your plist then the cordova build will continue. 脚本将运行,改变你的plist然后cordova构建将继续。
I find this cleaner as I don't like to have the platforms or plugins folder checked into version control on my Cordova projects. 我觉得这个更干净,因为我不喜欢在我的Cordova项目中将平台或插件文件夹检入版本控制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.