【问题标题】:Estimote beacon... didEnterInRegion doesn't call in Background估计信标... didEnterInRegion 不在后台调用
【发布时间】:2015-09-24 12:15:36
【问题描述】:

我需要使用 Estimote 信标。

当应用程序在前台时LocationMangaer委托方法didEnterInRegion结束didExitRegion被正确调用,但是当应用程序在后台(锁定屏幕)时出现问题。

如果我把设备放在桌子上,如果我带着 Estimate 信标走开,几米后会调用方法 didExitRegion

当我接近设备并进入信标区域(几厘米)时,方法didEnterInRegion 或方法didDetermineState 不会被调用。如果我解锁屏幕,几秒钟后,方法didEnterInRegion 会被调用。

这是我的代码:

NSUUID *beaconUUID = [[NSUUID alloc] initWithUUIDString:@"MYUUID"];
    NSString *regionIdentifier = @"FuelPay";
    CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:beaconUUID identifier:regionIdentifier];
    beaconRegion.notifyOnExit = YES;
    beaconRegion.notifyOnEntry = YES;
    beaconRegion.notifyEntryStateOnDisplay = YES;

    self.locationManager = [[CLLocationManager alloc] init];

    if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
        [self.locationManager requestAlwaysAuthorization];
    }
    self.locationManager.delegate = self;
    self.locationManager.pausesLocationUpdatesAutomatically = NO;

    [self.locationManager startMonitoringForRegion:beaconRegion];

Info.plist 中,我设置了 NSLocationAlwaysUsageDescription 属性并在项目功能中启用了后台模式(使用“使用蓝牙 LE 附件”)。

怎么了?

非常感谢!

【问题讨论】:

    标签: ios objective-c iphone bluetooth estimote


    【解决方案1】:

    后台监控与前台监控不同。由于扫描率降低(否则您的电池会消耗得太快),因此可能需要 一段时间(也以分钟为单位)来检测背景中的信标。

    尝试你的测试再等一会儿,如果 didExitRegion 被调用,它的对应 didEnterRegion 也应该被调用。

    无论如何,我假设在您检查didEnterRegion 之前,您之前已经执行了exit。我的意思是,如果您在信标范围内(例如,信标和设备在同一个房间内)启动应用程序,则永远不会调用didEnterRegion。所以你可以

    • 触发didExitRegion离开房间
    • 在范围内没有任何信标的情况下启动您的应用

    然后再次靠近你的信标

    【讨论】:

      猜你喜欢
      • 2014-08-30
      • 2015-02-05
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-22
      • 1970-01-01
      相关资源
      最近更新 更多