2016-08-23 64 views
0

我在我的cordova应用程序中安装了https://github.com/katzer/cordova-plugin-background-modehttps://github.com/katzer/cordova-plugin-local-notifications科尔多瓦应用程序监控在应用程序处于死亡状态时显示Estimote/iBeacon IOS

我试图在我的应用程序关闭时监视背景中的信标,并且一旦检测到信标并且处于区域中时发送通知。

使用这两个插件,当用户退出应用程序屏幕但应用程序仍然打开时,应用程序成功运行,但用户完全终止进程时不起作用。

这可以单独使用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 [常规 - >功能]中的设置,以便后台模式和推送通知处于打开状态。

该应用程序做它所需要的,即使在后台,并没有杀死,尽管一旦应用程序被杀害停止。我试图在应用处于离线状态时发送通知,指示信标处于范围内,以便用户可以打开应用。

回答

0

的几点:

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

  2. 信标监测必须在AppDelegate中进行配置和初始化。你不能依赖插件来做到这一点,因为当应用切换到前台时,它不一定会使信标监控处于活动状态。

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

相关问题