1 - (void)applicationDidEnterBackgtound 2 { 3 UIApplication *app = [UIApplication sharedApplication]; 4 __block UIBackgroundTaskIdentifier taskId; 5 6 taskId = [app beginBackgroundTaskWithExpirationHandler:^{ 7 NSLog(@"%@",NSStringFromSelector(_cmd)); 8 [app endBackgroundTask:taskId]; 9 }]; 10 11 if (taskId == UIBackgroundTaskInvalid) { 12 return; 13 } 14 15 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 16 //做一些额外的操作 17 [app endBackgroundTask:taskId]; 18 }); 19 }
时间: 2024-10-15 19:06:24