• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 在后台关闭 iBeacons 监控并关闭应用程序

[复制链接]
菜鸟教程小白 发表于 2022-12-13 10:27:02 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在使用 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)locationManagerCLLocationManager *)manager didDetermineStateCLRegionState)state forRegionCLRegion *)region{

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

}

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

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

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

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

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

谢谢!



Best Answer-推荐答案


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

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

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

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

关于ios - 在后台关闭 iBeacons 监控并关闭应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29264178/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap