当我的应用没有运行时,我很难解决这个问题。我已经实现了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...
}
“(。我也有在此之前的工作,它会给锁定屏幕上的通知,现在不工作)” ......你有什么改变? –
行..我确实了解了如何在后台和上面的问题已更新时再次使我的徽章出现在锁定屏幕上:[self.locationManager startMonitoringForRegion:rflBeacon]; –
这可能会帮助你:http://stackoverflow.com/questions/19127282/ibeacon-notification-when-the-app-is-not-running – random