PhoneGap:修改配置。向Info添加属性的xml。plist离子iOS

时间:2023-01-13 07:29:40

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

对于我的应用程序,我需要在Info中添加一些设置。为iOS plist文件。我认为最好的方法是将这些设置添加到我的配置中。xml文件(我正在使用PhoneGap)。当我在配置中添加以下内容时。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. The build show 'success', so I don't think there's a syntax error.

我的信息中没有添加任何内容。plist文件,我完全不知道为什么。构建显示了“成功”,所以我认为没有语法错误。

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?

但信息中没有添加任何内容。plist文件。我在这里做错了什么?

1 个解决方案

#1


5  

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

我使用iOS的构建挂钩来实现这一点。因此,在配置。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:

例如,这里我关闭了ios9对SSL安全后端url的要求,因为我开发的应用程序的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. Here I'm adding a dict and setting a boolean value but you can do a variety of other stuff as per PlistBuddy documentation.

我正在抑制plistbuddy的返回代码,因为如果项目已经存在,它将失败。这里我添加了一个命令并设置了一个布尔值,但是根据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项目上检查版本控制的平台或插件文件夹。

#1


5  

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

我使用iOS的构建挂钩来实现这一点。因此,在配置。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:

例如,这里我关闭了ios9对SSL安全后端url的要求,因为我开发的应用程序的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. Here I'm adding a dict and setting a boolean value but you can do a variety of other stuff as per PlistBuddy documentation.

我正在抑制plistbuddy的返回代码,因为如果项目已经存在,它将失败。这里我添加了一个命令并设置了一个布尔值,但是根据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项目上检查版本控制的平台或插件文件夹。