【问题标题】:iOS - Regionmonitoring in StandByiOS - StandBy 中的区域监控
【发布时间】:2018-05-21 04:39:33
【问题描述】:

我已经为信标(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 上测试

【问题讨论】:

  • 这是不寻常的行为。这表明在屏幕关闭的情况下根本没有执行蓝牙扫描。您是否在 AppDelegate 中设置了区域监控?
  • 是的。我在 AppDelegate.m 中开始监控

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


【解决方案1】:

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

显示的代码看起来不错,即使您愿意,我什至不知道有什么方法可以导致您描述的行为。一定有其他未知变量导致您的手机出现这种异常行为。我可能会尝试在另一部手机上进行测试,确认您没有看到这种行为,然后使用反复试验来尝试使手机的配置相同,直到您弄清楚丢失的变量是什么。

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

【讨论】:

    【解决方案2】:

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

    详情请看这里:http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html

    如那篇文章所述,您无需将位置更新后台模式设置为“是”。 此外,您不需要将 notifyOnExit 和 notifyOnEntry 指定为 true。

    希望这会有所帮助。

    【讨论】:

    • 我已经等了 1 个小时。在那一小时后,我打开 iPhone,2 秒后收到通知。
    猜你喜欢
    • 1970-01-01
    • 2013-11-20
    • 2011-07-17
    • 1970-01-01
    • 2014-05-23
    • 1970-01-01
    • 2015-12-09
    • 2011-09-19
    • 1970-01-01
    相关资源
    最近更新 更多