【问题标题】:Close iBeacons monitoring on background and with app closed在后台关闭 iBeacons 监控并关闭应用程序
【发布时间】:2015-05-29 15:01:56
【问题描述】:

我正在使用 IBeacon 构建一个简单的 ios 应用程序,我使用 startMonitoringForRegion 来检测信标。那是 AppDelegte.m 代码:​​

    NSUUID *beaconUUID = [[NSUUID alloc] initWithUUIDString:@"0040C159-12F6-4FC3-9189-87C069FFE5CF"];
    NSString *regionIdentifier = @"iBeacons region 1";
    self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID: beaconUUID identifier: regionIdentifier ];
    self.beaconRegion.notifyEntryStateOnDisplay = YES;
    self.locationManager = [[CLLocationManager alloc]init];
    self.locationManager.delegate = self;
    self.locationManager.pausesLocationUpdatesAutomatically = NO;
    [self.locationManager startMonitoringForRegion:self.beaconRegion];
    [self.locationManager startRangingBeaconsInRegion:beaconRegion];

然后在 didDetermineState 回调:

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{

    if (state == CLRegionStateInside) {
        //Start Ranging
        [manager startRangingBeaconsInRegion:(CLBeaconRegion*) region];
        NSLog(@"didDetermineState -->enter region");
    }
    else{
        //Stop Ranging
        [manager stopRangingBeaconsInRegion:(CLBeaconRegion*) region];
        NSLog(@"didDetermineState -->exit region");
    }

}

当 iBeacons 彼此远离时,这在前台、后台或关闭应用程序时都可以正常工作。但是当 iBeacons 彼此靠近时,我发现了一些问题。

在执行了几次测试后,我得出结论,RangingBeaconsInRegion 在后台或应用程序关闭时无法正常工作,只能进行监控。

当您进入或退出信标区域时,应用程序将在后台启动约 5 秒,并会收到对 didDetermineState: forRegion: 方法的回调。您可以在这 5 秒内在后台进行测距,之后 iOS 将再次暂停您的应用。

当 iBeacon 彼此远离时,这是完美的。当 iBeacon 距离太近,回调 didDetermineState: not called 退出 iBeacon 区域,然后进入下一个 iBeacon 区域时,就会出现问题。

有没有办法手动强制区域退出?或者其他解决这个问题的方法?

谢谢!

【问题讨论】:

  • 您好,如何在应用程序关闭时检查信标检测是否正常工作。我无法测试它。谢谢。
  • 您可以尝试发送本地通知,或在您的应用中创建记录。

标签: ios core-location ibeacon


【解决方案1】:

这是一个真正的问题。当信标具有重叠传输并且您的区域包含所有它们时,您将不会收到进入/退出事件,因为一个消失而另一个出现。

有很多方法可以解决这个问题,但没有一个是完美的解决方案。你可以:

  • 在后台将测距延长 3 分钟。
  • 构建您的信标标识符和区域,以便您尽可能多地获得退出/进入事件。

您可以在此处阅读第一种技术的更详细讨论:http://developer.radiusnetworks.com/2014/11/13/extending-background-ranging-on-ios.html

【讨论】:

  • 非常感谢您的帮助,我会尝试您的解决方案。我只需要博客上的演示吗?我没有太多的后台任务练习。无论如何,每次检测到 iBeacon 时停止并开始测距是一个疯狂的想法?
  • 我使用博客详细信息实现了您的第一个解决方案,它按预期工作。谢谢!!问候!
猜你喜欢
  • 1970-01-01
  • 2013-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多