Tools for Apache Cordova (VS2015): Adding custom entries to *info.plist for iOS

痴心易碎 提交于 2019-12-01 07:27:54

问题


I am using Tools for Apache Cordova on VS2015 to develop a project and I need to set some additional options in the *info.plist file in order to temporarily unblock HTTP web access (NsAppTransportSecurity) as well as enabling geolocation services to run in the background.

Basically, I need to add the following...

<key>UIBackgroundModes</key>
<array>
    <string>location</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>Location services are required.</string>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

According to my understanding of the Microsoft documentation here, also referenced by the SO question here, Tools for Apache Cordova allows you to add a *info.plist file to the /res/native/ios folder to be used in place of any generated file. I cannot however get this to work.

The documentation above is (in my opinion) a little confusing as to the naming of the file...

Place a custom Info.plist file in the res/native/ios/config.xml display name folder to override settings like splashscreens or icons. The Info.plist filename must be renamed as follows: config.xml display name-Info.plist to update iOS framework keys.

This is where I think I may be going wrong; I simply cannot work out what the name of the file should be.

Given a project "display name" of "My project" (as specified on the "Common Tab", "Display Name" when viewing the config.xml in the designer), I would assume the file name to have been "My project-Info.plist" or possibly "config.xml My project-Info.plist". I am also not sure if I should be creating another sub folder to contain the file...

Place a custom Info.plist file in the res/native/ios/config.xml display name folder

However whichever of these file names that I use if I then open the project in Xcode after it has been built (the remotebuild/taco subsystems leave a copy of the project in the ~/.taco_home/remote-builds/taco-remote/builds/nnn/cordovaApp/platforms/ios/My Project" folder until you close the remotebuild server), and look at the plist that has been submitted with the build my settings are not present.

I have also found that there is a "My project-Info.plist" in the "Platforms/ios/My Project" folder but if I make changes to this copy of the file again they do not filter through to the Mac for building.

Can anybody please verify the folder and filename that I am supposed to use. I know that the SO question that I referred to above was back in February and as such will have been referring to one of the preview builds and knowing that the format of the projects has changed between then and the RTM it may simply be that I am following out of date instruction.

Thanks.


回答1:


You can create a plugin to do this. This is what the plugin.xml will look like:

<plugin ...> <platform name="ios"> <config-file target="*-Info.plist" parent="UIStatusBarHidden"> <true/> </config-file> <config-file target="*-Info.plist" parent="UIViewControllerBasedStatusBarAppearance"> <false/> </config-file> </platform> </plugin>

This is a good reference: https://github.com/leecrossley/cordova-plugin-transport-security




回答2:


Ok, I have finally worked out how this works. Given the example display name of "My project" above...

  • The plist file should be named "My project-Info.plist"
  • The file should be placed in the folder "res/native/ios/My project"

I guess that the reference in the documentation to "config.xml display name" does actually make sense in as much as it refers to the "Display Name" from the common tab when viewing "config.xml" in the designer (though the element is actually named "name"). I still do not think this is very clear though!

Note however that the file will be used instead of the generated file, and that any changes made to the config.xml will NOT be reflected in this file (you will instead have to replicate these changes manually).

It is therefore suggested that you start with a copy of the original file which can be found at "platforms/ios/{display name}/{display name}-Info.plist", or sticking with the example, "platforms/ios/My project/My project-Info.plist".



来源:https://stackoverflow.com/questions/32744175/tools-for-apache-cordova-vs2015-adding-custom-entries-to-info-plist-for-ios

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