CLLocationManager didEnterRegion:与应用程序暂停时使用iBeacon

我试图唤醒我的应用程序(重新启动它),当它进入我定义的信标区域,但我不能得到它的工作。 这是我正在使用的步骤和代码。

  1. 将“位置更新”后台模式设置为YES。
  2. 监视我的CLBeaconRegion

    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"EBEFD083-70A2-47C8-9837-E7B5634DF524"]; beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"daRegion"]; beaconRegion.notifyEntryStateOnDisplay = NO; beaconRegion.notifyOnEntry = YES; beaconRegion.notifyOnExit = YES; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; [self.locationManager startMonitoringForRegion:beaconRegion]; 
  3. 实现委托方法

     - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region; - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region; - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region; 

任何我可能会错过的东西? 我已阅读文档,博客文章,论坛,似乎没有任何工作。 这是我阅读的网站之一, 这是另一个。

评论“我不能工作,当应用程序被杀害”是至关重要的。

如果您使用iOS7应用程序切换器杀死某个应用程序(例如,通过向上滑动应用程序图标),则在进入或离开iBeacon区域时,您将无法在后台重新启动应用程序。 这是devise – 如果用户不想让应用程序运行,那么Apple认为代码不应该使其重新启动。 看到这个线程。

幸运的是,用户通常不会这样做。 出于testing目的,如果你想完全停止一个应用程序,不要这样做。 重新启动您的手机。 (但是请注意,启动后需要一分钟左右才能检测到iBeacons。)

编辑2014年3月10日:这一行为已经改变了iOS 7.1的发布。 从任务切换器中杀死一个应用程序不再阻止它在后台检测到iBeacons。