当我的应用程序进入我定义的信标区域时,我试图唤醒它(重新启动它),但我就是无法让它工作。这是我正在使用的步骤和代码。
监控我的 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];
实现委托(delegate)方法
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region;
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;
有什么我可能遗漏的吗?我已经阅读了文档、博客文章、论坛,但似乎没有任何效果。 This是我阅读的网站之一,this是另一个。
最佳答案
评论“当应用程序被终止时我无法让它工作”很关键。
如果您使用 iOS7 应用程序切换器终止应用程序(例如,通过在应用程序图标上向上滑动),那么您将无法在进入或离开 iBeacon 区域时在后台重新启动该应用程序。这是设计使然——如果用户不希望该应用程序运行,那么 Apple 认为代码不应该能够使其重新启动。 See this thread.
幸运的是,用户通常不会这样做。出于测试目的,如果您想完全停止应用程序,请不要这样做。而是重新启动手机。 (但是请注意,启动后需要一分钟左右的时间才能检测到 iBeacon。)
编辑 2014/03/10:自 iOS 7.1 发布以来,此行为已更改。从任务切换器中终止应用程序不再阻止它在后台检测 iBeacon。
关于ios - CLLocationManager didEnterRegion : with iBeacon while app is suspended,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21124528/