2

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 数组!

4

3 回答 3

4

是的,这似乎是 Cordova 处理 plist 文件的插件配置设置中的一个错误。

重复的数组条目很烦人,但不应破坏构建或影响应用程序。但是,添加到 NSMainNibFile* 设置中的空格确实会导致 XCode 无法构建并NSInternalInconsistencyException显示您看到的错误消息。

在解决此问题之前,我正在使用以下钩子脚本解决它 - 放置在.cordova/hooks/after_platform_add/patch_plist.sh

#!/bin/bash
if pushd platforms/ios 2>/dev/null ; then   # iOS-specific actions...
    # Patch *-Info.plist
    PROJNAME=$(echo *.xcodeproj|sed -e 's/\..*//')
    sed -i '' '/<key>NSMainNibFile<\/key>/,/<\/string>/d' $PROJNAME/*-Info.plist
    sed -i '' '/<key>NSMainNibFile~ipad<\/key>/,/<\/string>/d' $PROJNAME/*-Info.plist
    popd
fi

这会从 plist 中完全删除这些设置,因为它们不是必需的。删除它们可以防止 Cordova 在prepare.

该脚本需要可执行:

chmod a+x .cordova/hooks/after_platform_add/patch_plist.sh

这应该在platform add生成 plist 时在每个命令之后运行 - 因此您需要在之后运行以下命令来重新生成它并应用补丁:

cordova platform rm ios -d
cordova platform add ios -d
于 2013-09-05T10:45:11.387 回答
1

这不是一个好的解决方案,但我发现在plugman中修复之前可以防止重复的方法如下:

<!-- clobber old array value in .plist -->
<config-file target="*-Info.plist" parent="UIBackgroundModes">
    <string>CLOBBER</string>
</config-file>

<!-- replace clobbered value with proper array in .plist -->
<config-file target="*-Info.plist" parent="UIBackgroundModes">
    <array>
        <string>location</string>
    </array>
</config-file>

即,用一维节点破坏节点,然后用适当的数组重新破坏它。

于 2013-11-26T16:53:31.727 回答
0

只需将这些行添加到 config.xml

<platform name="ios">
    <config-file platform="ios" target="*-Info.plist" parent="NSMainNibFile">
        <string></string>
    </config-file>
</platform>
<platform name="ios">
    <config-file platform="ios" target="*-Info.plist" parent="NSMainNibFile~ipad">
        <string></string>
    </config-file>
</platform>
于 2017-03-17T13:47:45.313 回答