- - (void) doUpdate
- {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- [self beginBackgroundUpdateTask];
- NSURLResponse * response = nil;
- NSError * error = nil;
- NSData * responseData = [NSURLConnection sendSynchronousRequest: request returningResponse: &response error: &error];
- // Do something with the result
- [self endBackgroundUpdateTask];
- });
- }
- - (void) beginBackgroundUpdateTask
- {
- self.backgroundUpdateTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
- [self endBackgroundUpdateTask];
- }];
- }
- - (void) endBackgroundUpdateTask
- {
- [[UIApplication sharedApplication] endBackgroundTask: self.backgroundUpdateTask];
- self.backgroundUpdateTask = UIBackgroundTaskInvalid;
- }
iOS 后台任务
最新推荐文章于 2023-08-02 17:15:59 发布