我想 24x7 次获取我设备的位置。但根据苹果文档,应用程序最多只能运行 10 分钟。之后,应用程序会自动被杀死。我正在使用以下代码:
- (void)applicationWillResignActive:(UIApplication *)application
{
UIApplication * app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler: ^ {
dispatch_async (dispatch_get_main_queue (), ^ {
if (bgTask != UIBackgroundTaskInvalid)
{
[app endBackgroundTask: bgTask];
bgTask = UIBackgroundTaskInvalid;
}
});
}];
// Start the long-running task and return immediately.
dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
lm.locationManager.distanceFilter = kCLDistanceFilterNone;
lm.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[lm.locationManager startMonitoringSignificantLocationChanges];
[lm.locationManager startUpdatingLocation];
dispatch_async (dispatch_get_main_queue (), ^ {
if (bgTask != UIBackgroundTaskInvalid) {
[app endBackgroundTask: bgTask];
bgTask = UIBackgroundTaskInvalid;
}
});
});
}
我还将支持的背景模式包括为Requires location。
但该应用程序仅运行 10 分钟。我怎样才能让应用程序一直运行。请帮帮我!