当应用程序处于被杀死状态IOS时,Cordova Application Monitoring evothings Estimote / iBeacon

时间:2016-08-23 16:16:03

标签: ios objective-c cordova estimote beacon

我在我的cordova应用程序中安装了https://github.com/katzer/cordova-plugin-background-modehttps://github.com/katzer/cordova-plugin-local-notifications

当我的应用关闭时,我正在尝试监控后台中的信标,并在检测到信标并且在区域内时发送通知。

使用这两个插件,当用户退出应用程序屏幕但应用程序仍处于打开状态时应用程序成功运行,但是当用户完全杀死该进程时该应用程序仍然无效。

这可以单独使用Javascript完成还是我必须修改AppDelegate.m中的代码?

我使用以下代码尝试了这个:

#import "AppDelegate.h"
#import "MainViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface AppDelegate ()
@property (nonatomic, strong) CLLocationManager *locationManager;
@property(nonatomic, assign) BOOL notifyEntryStateOnDisplay;
@end


@implementation AppDelegate



- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    self.viewController = [[MainViewController alloc] init];

    self.locationManager = [[CLLocationManager alloc] init];

    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{

    UILocalNotification *notification = [[UILocalNotification alloc] init];
    NSLog(@"BLUETOOTH");
    if(state == CLRegionStateInside)
    {
        notification.alertBody = [NSString stringWithFormat:@"You are inside region %@", region.identifier];
    }
    else if(state == CLRegionStateOutside)
    {
        notification.alertBody = [NSString stringWithFormat:@"You are outside region %@", region.identifier];
    }
    else
    {
        return;
    }

    [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

@end

虽然应用程序没有启动。我也改变了我的xCode中的设置[General - &gt;功能]使背景模式和推送通知处于开启状态。

该应用程序即使在后台也可以执行所需的操作,但是一旦应用程序被杀,应用程序就会停止。我正在尝试在应用离线时发送通知信号在范围内,以便用户可以开启应用。

1 个答案:

答案 0 :(得分:0)

几点:

  1. 您必须设置self.locationManager.delegate=self,并使AppDelegate实现CLLocationManagerDelegate协议,特别是在发现信标时应调用的didEnterRegion方法。

  2. 必须在AppDelegate中配置和初始化信标监控。您无法依赖插件执行此操作,因为当应用切换到前台时,它不一定会使信标监控处于活动状态。

  3. 测试时,在AppDelegate的didEnterRegion方法中设置日志消息或断点,以便知道它是否被调用。