iOS - StandBy中的区域监控

时间:2017-12-07 06:23:46

标签: ios objective-c cllocationmanager ibeacon region-monitoring

我已经为信标实现了监控功能(didEnterRegion)。 如果我使用iPhone,它的效果很好。 (应用程序位于前台,后台或仅安装和关闭,但我的iPhone必须正在使用(屏幕上)。)

如果我的手机处于StandBy模式(按下顶部按钮),我不会收到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];
}

项目设置: 推送通知已启用。 位置更新的背景模式,backgroudn fetch,使用蓝牙LE配件。

在iOS 11.1上测试

2 个答案:

答案 0 :(得分:0)

您等待背景检测多久了?这可能需要15分钟。

详情请见此处:http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html

如该文章所述,您无需将位置更新背景模式设置为YES。 此外,您不需要将notifyOnExit和notifyOnEntry指定为true。

希望这可能会有所帮助。

答案 1 :(得分:0)

问题中描述的行为是不寻常的,它与我在设备上看到的体验不符。您绝对应该使用黑屏进行didEnterRegion调用,并且我在iOS 7-11.x上有几个应用程序,我已经看到了这种情况。

显示的代码看起来不错,即使您愿意,我甚至不知道如何导致您描述的行为。必须有一些其他未知变量导致您的手机出现这种异常行为。我可能会尝试在另一部手机上进行测试,验证您没有看到此行为,然后使用反复试验尝试制作手机'配置完全相同,直到你弄清楚丢失的变量是什么。

抱歉,我知道这不是一个简单的答案。