plugin.xml的一部分
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="MyPlugin">
<param name="ios-package" value="MyPlugin"/>
</feature>
</config-file>
<!--this need to be added to the .plist file-->
<config-file target="*-Info.plist" parent="UIBackgroundModes">
<array>
<string>location</string>
</array>
</config-file>
<header-file src="src/ios/MyPlugin.h" />
<source-file src="src/ios/MyPlugin.m" />
</platform>
左侧是安装我的插件之前,右侧是之后:
如您之前所见:
<key>NSMainNibFile</key>
<string></string>
<key>NSMainNibFile~ipad</key>
<string></string>
之后
<key>NSMainNibFile</key>
<string>
</string>
<key>NSMainNibFile~ipad</key>
<string>
</string>
多么大的不同!如果我删除那些我不知道它们来自哪里的空格,那么我在启动后就不会崩溃!
ios 6 模拟器输出(但在设备上也相同)
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/myusername/Library/Application Support/iPhone Simulator/6.0/Applications/F4FDE3C4-D7A8-440F-866D-D0DECD79E2F5/My.app> (loaded)' with name '
''
*** First throw call stack:
(0xea012 0x2848e7e 0xe9deb 0x540fac 0x54298d 0x324ceb 0x325002 0x323ed6 0x335315 0x33624b 0x327cf8 0x367adf9 0x367aad0 0x5fbf5 0x5f962 0x90bb6 0x8ff44 0x8fe1b 0x3237da 0x32565c 0x1fe3c 0x1fd9d)
libc++abi.dylib: terminate called throwing an exception
(lldb)
我认为这是 Cordova / Phonegap 中的一个错误,但这并不能让我的老板高兴。如何解决这个问题?每次从命令行启动时都会重新生成 .plist,因此无法手动编辑。
找不到文档,只有这个,我不知道为什么我的位置被添加了 4 次,如果我只写了 1 次。
编辑:从命令行安装我的插件(但不编译或运行)后,plist 如下所示:
<key>NSMainNibFile</key>
<string>
</string>
<key>NSMainNibFile~ipad</key>
<string>
</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
$ phonegap build ios
<key>NSMainNibFile</key>
<string>
</string>
<key>NSMainNibFile~ipad</key>
<string>
</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
<string>location</string>
</array>
- 观察:有一行添加了位置!
$ phonegap run ios
[phonegap] detecting iOS SDK environment...
[phonegap] using the local environment
[phonegap] compiling iOS...
[phonegap] successfully compiled iOS app
[phonegap] trying to install app onto device
[phonegap] no device was found
[phonegap] trying to install app onto emulator
[phonegap] successfully installed onto emulator
plist 将被清除 2 次:那些将被清除 2 次,最后将再次添加。现在 plist 看起来像这样:
<key>NSMainNibFile</key>
<string>
</string>
<key>NSMainNibFile~ipad</key>
<string>
</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
<string>location</string>
<string>location</string>
<string>location</string>
<string>location</string>
</array>
编辑2:
cordova prepare
随机清除<string></string>
空格并始终添加<string>location</string>
到 UIBackgroundModes 数组!