【发布时间】:2013-10-09 02:58:01
【问题描述】:
当应用程序未运行时,我很难让它工作。我实现了locationManager:didRangeBeacons:inRegion:,当应用程序在前台或后台运行时调用它,但是当我退出应用程序并锁定屏幕时它似乎没有做任何事情。位置服务图标消失了,我从不知道我进入了信标范围。 LocalNotification 是否仍然有效?
我在后台模式 (XCode 5) 中选择了位置更新和使用蓝牙 LE 配件,我认为我不需要它们。
非常感谢任何帮助。
-(void)watchForEvents { // this is called from application:didFinishLaunchingWithOptions
id class = NSClassFromString(@"CLBeaconRegion");
if (!class) {
return;
}
CLBeaconRegion * rflBeacon = [[CLBeaconRegion alloc] initWithProximityUUID:kBeaconUUID identifier:kBeaconString];
rflBeacon.notifyOnEntry = YES;
rflBeacon.notifyOnExit = NO;
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startRangingBeaconsInRegion:rflBeacon];
[self.locationManager startMonitoringForRegion:rflBeacon];
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
if (beacons.count == 0 || eventRanged) { // breakpoint set here for testing
return;
}
eventRanged = YES;
if (backgroundMode) { // this is set in the EnterBackground/Foreground delegate calls
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = [NSString stringWithFormat:@"Welcome to the %@ event.",region.identifier];
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
// normal processing here...
}
【问题讨论】:
-
“(我之前确实有这个工作,它会在锁定屏幕上发出通知。现在这不起作用。)”......你改变了什么?
-
OK.. 我确实找到了如何在后台和上面的问题更新时让我的徽章再次出现在锁定屏幕上:[self.locationManager startMonitoringForRegion:rflBeacon];
-
我在研究这个问题时看到了这一点。根据那个答案,它应该自动发生。显然,这对我来说并不是那么自动:(
-
应该在 iOS 7.1 上修复。是吗? beekn.net/2014/03/…