0

背景

我正在开发一个必须作为服务运行的 Cordova 应用程序,即在后台继续运行并在设备运行时重新启动。据我所知,在 iOS 上,这只是正确设置 UIBackgroundModes 的一种情况,但在 Android 上需要更多的努力,并且需要显式启动服务。

我已经根据 Mark Taylor 的示例为 Android 开发了一个插件

目前我调用了一些 JSdeviceready来启动 Android 代码,但不需要为 iOS 做任何事情。

问题

我应该如何打包我的插件,以便它可以在零配置的所有平台上运行。在我的主 JS中编写语句似乎很笨拙,if (Device.type == 'android')但我真的不想编写本机 null 实现。

有没有建议的方法?

4

1 回答 1

1

使用此处<js-module>描述的标签弄清楚了。

将此添加到我的plugin.xml

<platform name='android'>
    ...
    <js-module src="androidSpecificStuff.js" name="SomeModule">
        <clobbers target="SomeModule" />
    </js-module>
    ...
</platform>

然后在androidSpecificStuff.js有如下代码:

document.addEventListener('deviceready', function () {
    // do android-specific initialisation here  
})
于 2013-09-05T07:12:13.253 回答