cordova 3.0插件plist配置

时间:2013-09-04 15:31:59

标签: ios plugins cordova info.plist

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>

左侧是安装我的插件之前,右侧是After:

Difference

如您所见:

<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,因此无法手动编辑。

找不到文档,只有this而且我不知道为什么我的位置被添加了4次,如果我只写了一次。

编辑: 从命令行安装我的插件(但不编译或运行)后,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>

-observe:有一行添加了位置!

$ 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>

EDIT2:

cordova prepare

RANDOMLY 清除<string></string>个空格并始终将<string>location</string>添加到UIBackgroundModes数组中!

3 个答案:

答案 0 :(得分: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

答案 1 :(得分: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>

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

答案 2 :(得分:0)

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

即可
{{1}}