从暂停状态唤醒应用程序进入信标进入太长时间

时间:2016-03-08 17:38:34

标签: ios core-location ibeacon

我有一个监控iBeacons的应用程序。当应用程序从挂起状态终止然后进入它正在监视的信标区域时,有时需要很长时间(有时长达1分钟)才能唤醒应用程序(调用didEnterRegion或didExitRegion)。我能做些什么吗?这是我在应用程序进入后台时使用的代码

- (void)extendBackgroundRunningTime {
    if (_backgroundTask != UIBackgroundTaskInvalid) {
        // if we are in here, that means the background task is already running.
        // don't restart it.
        return;
    }
    // Attempt to extend background time by initializing a placeholder background thread
    __block Boolean self_terminate = YES;
    _backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithName:kBISBeaconManagerKeyBackgroundTask expirationHandler:^{
        // Background task expired, completion
        if (self_terminate) {
            NSLog(@"Application Terminated");
            [[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
            _backgroundTask = UIBackgroundTaskInvalid;
        }
    }];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // Background task started
    });
}

1 个答案:

答案 0 :(得分:3)

一些想法:

  • 问题中显示的代码扩展了背景信标测距时间。 没有做任何影响信标监控的事情(监控API提供了didEnterRegion和didExitRegion回调)。

  • 监控响应时间可能会有很大差异。 最佳情况,didEnterRegion回调将在范围内的第二个或两个信标内触发。 didExitRegion事件总是延迟30秒(这是iOS在决定信标不再可见之前等待的时间。)

  • 如果采用所有30个蓝牙硬件加速插槽,则无法满足最佳情况场景时间。这些插槽位于手机上的所有应用中。如果您的应用尝试在拍摄所有广告位时监控信标区域,检测时间将回退到软件备份周期,可能需要15分钟

有关详细信息,请参阅此处: http://developer.radiusnetworks.com/2014/03/12/ios7-1-background-detection-times.html

http://developer.radiusnetworks.com/2015/04/21/max-beacon-regions-ios.html

相关问题