2016-11-21 74 views

回答

1

即使应用程序未运行,位置事件(与本示例中的信标相关)的处理方式与其他任何应用程序启动事件的处理方式相同。每次手机在应用程序终止时进入或退出某个区域时,都会自动启动。

应用中:didFinishLaunchingWithOptions:方法(AppDelegate类的)称为与UIApplicationLaunchOptionsLocationKey键存在于launchOptions参数。

当您验证此密钥存在时(因此位置是您的应用程序启动的原因),您应该创建ESTBeaconManager类的新实例,将委派设置为AppDelegate对象(或任何其他正在以ESTBeaconManagerDelegate工作并且之前创建的对象发生此事件)并开始监控。你传递给startMonitoringForRegion

地区:方法并不重要,因为ESTBeaconManager代表将获得最新的区域信息。您可以选择您的应用在iOS中注册的任何应用。监控撤销后,应用程序将自动接收beaconManager:didEnterRegionbeaconManager:didExitRegion:方法中最近进入/退出的地区事件。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    if([launchOptions objectForKey:@"UIApplicationLaunchOptionsLocationKey"]) 
    { 
    self.beaconManager = [ESTBeaconManager new]; 
    self.beaconManager.delegate = self; 
    // don't forget the NSLocationAlwaysUsageDescription in your Info.plist 
    [self.beaconManager requestAlwaysAuthorization]; 
    [self.beaconManager startMonitoringForRegion:[[ESTBeaconRegion alloc] 
                initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID 
                identifier:@"AppRegion"]]; 
    } 
    return YES; 
} 

-(void)beaconManager:(ESTBeaconManager *)manager didEnterRegion:(ESTBeaconRegion *)region 
{ 
    UILocalNotification *notification = [[UILocalNotification alloc] init]; 
    notification.alertBody = @"Enter region"; 
    notification.soundName = UILocalNotificationDefaultSoundName; 

    [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; 
} 

-(void)beaconManager:(ESTBeaconManager *)manager didExitRegion:(ESTBeaconRegion *)region 
{ 
    UILocalNotification *notification = [[UILocalNotification alloc] init]; 
    notification.alertBody = @"Exit region"; 
    notification.soundName = UILocalNotificationDefaultSoundName; 

    [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; 
} 
+0

这些方法已经被添加,但仍是其无法正常工作。 – Megha

+0

然后发生什么是有任何错误。具体 –

+0

谢谢!它运作良好。 – Megha

相关问题