PhoneGap:修改config.xml以添加属性到Info.plistion iOS [英] PhoneGap: modify config.xml to add properties to Info.plist ion iOS
问题描述
对于我的应用程序,我需要添加一些设置到iOS的Info.plist文件。我认为最好的方法来做到这一点,将这些设置添加到我的config.xml文件(我使用PhoneGap)。当我将以下内容添加到config.xml文件并运行
cordova build ios
或
cordova更新平台ios
没有什么添加到我的Info.plist文件,我绝对不知道为什么。
我试过:
< platform name =ios>
< allow-intent href =itms:*/>
< allow-intent href =itms-apps:*/>
< config-file target =* - Info.plistparent =NSAppTransportSecurity>
< array>
< dict>
< key> NSExceptionDomains< / key>
< array>
& lt; dict>
< key> s3.amazonaws.com< / key>
< array>
< dict>
<! - 包含以允许子域 - >
< key> NSIncludesSubdomains< / key>
< true />
<! - 包含以允许不安全的HTTP请求 - >
< key> NSTemporaryExceptionAllowsInsecureHTTPLoads< / key>
< true />
<! - 包含以指定最小TLS版本 - >
< key> NSTemporaryExceptionMinimumTLSVersion< / key>
< string> TLSv1.1< / string>
< / dict>
< / array>
< / dict>
< / array>
< / dict>
< / array>
< / config-file>
< / platform>
和
< platform name =ios>
< allow-intent href =itms:*/>
< allow-intent href =itms-apps:*/>
< config-file target =* - Info.plistparent =NSAppTransportSecurity>
< dict>
< key> NSExceptionDomains< / key>
< dict>
< key> s3.amazonaws.com< / key>
< dict>
<! - 包含以允许子域 - >
< key> NSIncludesSubdomains< / key>
< true />
<! - 包含以允许不安全的HTTP请求 - >
< key> NSTemporaryExceptionAllowsInsecureHTTPLoads< / key>
< true />
<! - 包含以指定最小TLS版本 - >
< key> NSTemporaryExceptionMinimumTLSVersion< / key>
< string> TLSv1.1< / string>
< / dict>
< / dict>
< / dict>
< / config-file>
< / platform>
和
< gap:config-file platform =iosparent =NSAppTransportSecurity>
< dict>
< key> NSExceptionDomains< / key>
< dict>
< key> s3.amazonaws.com< / key>
< dict>
<! - 包含以允许子域 - >
< key> NSIncludesSubdomains< / key>
< true />
<! - 包含以允许不安全的HTTP请求 - >
< key> NSTemporaryExceptionAllowsInsecureHTTPLoads< / key>
< true />
<! - 包含以指定最小TLS版本 - >
< key> NSTemporaryExceptionMinimumTLSVersion< / key>
< string> TLSv1.1< / string>
< / dict>
< / dict>
< / dict>
< / gap:config-file>
和
< gap:config-file platform =iosparent =NSAppTransportSecurity>
< array>
< dict>
< key> NSExceptionDomains< / key>
< array>
< dict>
< key> s3.amazonaws.com< / key>
< array>
< dict>
<! - 包含以允许子域 - >
< key> NSIncludesSubdomains< / key>
< true />
<! - 包含以允许不安全的HTTP请求 - >
< key> NSTemporaryExceptionAllowsInsecureHTTPLoads< / key>
< true />
<! - 包含以指定最小TLS版本 - >
< key> NSTemporaryExceptionMinimumTLSVersion< / key>
< string> TLSv1.1< / string>
< / dict>
< / array>
< / dict>
< / array>
< / dict>
< / array>
< / gap:config-file>
但没有任何内容添加到Info.plist文件。我在这里做错了什么?
我使用iOS的构建钩子实现。所以,在config.xml中我会像:
< hook type =before_buildsrc =.. /scripts/ios_before_build.sh/>
内部:
< platform name=ios>
在config.xml中的元素
我将创建一个名为../scripts/ios_before_build.sh的文件,确保它有执行权限(chmod 755 ../scripts/ios_before_build.sh),然后设置脚本使用PlistBuddy对.plist文件进行必要的更改。
例如,我在关闭iOS 9对SSL安全后端网址的要求,因为我开发的应用程序的API不使用https:
val = $(/ usr / libexec / plistbuddy -cadd NSAppTransportSecurity:NSAllowsArbitraryLoads bool trueplatforms / ios / AppName / AppName- plist 2> / dev / null)
p $ p>
我抑制plistbuddy的返回代码,如果项目已存在。这里我添加一个dict并设置一个布尔值,但你可以根据
然后当你这样做:
<$>cordova build ios
脚本将运行,
我发现这个更清洁,因为我不喜欢在我的Cordova项目的版本控制中检查平台或插件文件夹。 / p>
For my application, I need to add some settings to the Info.plist file for iOS. I thought the best way to do this, would be to add these settings to my config.xml file (I'm using PhoneGap). When I add the following to the config.xml file and run
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. 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. What am I doing wrong here?
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.
这篇关于PhoneGap:修改config.xml以添加属性到Info.plistion iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!