从 Beacon Enter 上的暂停状态唤醒应用程序花费的时间太长
Wake Application from Suspended state on Beacon Enter taking too long
我有一个监控 iBeacon 的应用程序。当应用程序从挂起状态终止,然后进入它正在监视的信标区域时,有时可能需要很长时间(有时长达 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
});
}
一些想法:
问题中显示的代码 延长了背景信标测距时间。它不会影响信标监控(监控 API 提供 didEnterRegion 和 didExitRegion 回调)。
监控响应时间可能会有很大差异。 最好的情况是,didEnterRegion 回调将在一秒内触发 或两个信标在范围内。 didExitRegion 事件总是延迟 30 秒(这是 iOS 在决定信标不再可见之前等待的时间。)
如果所有 30 个蓝牙硬件加速插槽都被占用,则无法满足最佳情况下的时间。这些插槽横跨 phone 上的所有应用程序。如果您的应用在所有时隙都已占用时尝试监控信标区域,检测时间会回落到软件备份周期,可能需要 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
我有一个监控 iBeacon 的应用程序。当应用程序从挂起状态终止,然后进入它正在监视的信标区域时,有时可能需要很长时间(有时长达 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
});
}
一些想法:
问题中显示的代码 延长了背景信标测距时间。它不会影响信标监控(监控 API 提供 didEnterRegion 和 didExitRegion 回调)。
监控响应时间可能会有很大差异。 最好的情况是,didEnterRegion 回调将在一秒内触发 或两个信标在范围内。 didExitRegion 事件总是延迟 30 秒(这是 iOS 在决定信标不再可见之前等待的时间。)
如果所有 30 个蓝牙硬件加速插槽都被占用,则无法满足最佳情况下的时间。这些插槽横跨 phone 上的所有应用程序。如果您的应用在所有时隙都已占用时尝试监控信标区域,检测时间会回落到软件备份周期,可能需要 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