我有一个应用程序(iOS 7+),一旦应用程序进入后台,我需要在"n“分钟(总是大于3分钟)后调用goes服务。在对该the服务进行调用之后,需要每隔45秒调用另一个the服务。
对webservice的调用需要用户的当前位置。因此,我将获取用户的位置,并且在info.plist文件中也有相应的条目。
我在applicationdidEnterBackground中有以下代码
CLLocationManager * manager = [[CLLocationManager alloc]init];
__block UIBackgroundTaskIdentifier background_task;
background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[manager startUpdatingLocation];
while(TRUE)
{
//backgroundTimeRemaining time does not go down.
NSLog(@"Background time Remaining: %f",[[UIApplication sharedApplication] backgroundTimeRemaining]);
[NSThread sleepForTimeInterval:1]; //wait for 1 sec
}
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
});你能告诉我如何在后台运行应用程序"n“分钟,它总是大于3。
发布于 2014-07-11 15:08:00
请参阅后台获取处理程序。在某些限制下,它可以帮助您。
https://stackoverflow.com/questions/24691159
复制相似问题