【发布时间】:2016-06-22 19:14:59
【问题描述】:
我有一个监控 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
});
}
【问题讨论】:
标签: ios core-location ibeacon