我已经为信标(didEnterRegion)实现了一个监控功能。如果我使用我的 iPhone,它会很好用。(应用程序在前台、后台或仅安装并关闭,但我的 iPhone 必须在使用中(屏幕打开)。)
如果我的手机处于待机模式(按下顶部按钮),我不会收到 didEnterRegion 的通知。如果我使用手机(屏幕打开),会弹出通知。是否有机会在待机模式下也获得 didEnterRegion 事件?
self->beaconLocationManager = [[CLLocationManager alloc] init];
[self->beaconLocationManager requestAlwaysAuthorization];
self->beaconLocationManager.delegate = self;
beaconLocationManager.allowsBackgroundLocationUpdates = YES;
NSString* beaconIdentName = [NSString stringWithFormat:@"Beacon%d", cnt];
NSUUID *uuid2=[[NSUUID alloc]initWithUUIDString:uuid];
clBeconRegion2=[[CLBeaconRegion alloc]initWithProximityUUID:uuid2 identifier:beaconIdentName];
clBeconRegion2.notifyOnEntry=YES;
clBeconRegion2.notifyEntryStateOnDisplay = NO;
[self->beaconLocationManager startMonitoringForRegion:clBeconRegion2];
[self->beaconLocationManager startRangingBeaconsInRegion:clBeconRegion2];
...
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(@"ENTER REGION");
UILocalNotification *localNotification = [[UILocalNotification alloc]init];
localNotification.alertBody = @"FOUNDED";
localNotification.alertAction = [NSString stringWithFormat:@"%@ Connecting...", region.identifier];
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotification];
}
项目设置:推送通知已开启。用于位置更新、背景获取、使用蓝牙 LE 配件的后台模式已开启。
在 iOS 11.1 上测试