确定后台的操作系统是否启动了cordova应用程序

时间:2016-05-23 16:48:51

标签: cordova cordova-ios

我们在cordova ios应用程序中使用了几个插件,可以在后台启动应用程序。特别是这两个插件:https://github.com/petermetz/cordova-plugin-ibeaconhttps://github.com/oursiberia/cordova-plugin-visit。不幸的是,当应用程序在后台启动时,似乎无法通过cordova告知它在后台运行。我正在注册暂停,恢复,活动和设备准备事件,在这种情况下唯一的事件是deviceready,如果应用程序是由用户在前台启动的,它也是在cordova中传递的唯一通知。在ios本机应用程序中,我将能够检查didFinishLaunchingWithOptions中的launchOptions以查看它是否使用UIApplicationLaunchOptionsLocationKey启动,或者我可以检查[[UIApplication sharedApplication] applicationState]以确定应用程序是否在后台运行。有没有办法确定应用程序是在cordova的后台启动还是在任何人都知道的任何cordova插件中启动?我一直在网上搜索一段时间没找到任何东西。

1 个答案:

答案 0 :(得分:0)

我最终编写了自己的插件来执行此操作。以下是确定应用程序是否在ios后台运行时所做的工作:

- (void)isAppRunningInForeground:(CDVInvokedUrlCommand *)command {
NSLog(@"- CDVAppState isAppRunningInForeground");
CDVPluginResult* result = [CDVPluginResult
                           resultWithStatus:CDVCommandStatus_OK
                           messageAsBool:[[UIApplication sharedApplication] applicationState] == UIApplicationStateActive];

[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];

}