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