【Multitasking】Executing a Finite-Length Task in the Background

来源:互联网 发布:淘宝联名卡怎么申请 编辑:程序博客网 时间:2024/06/05 18:55
//Starting a background task at quit time- (void)applicationDidEnterBackground:(UIApplication *)application  {      bgTask = [application beginBackgroundTaskWithExpirationHandler:^{          // Clean up any unfinished task business by marking where you          // stopped or ending the task outright.          [application endBackgroundTask:bgTask];          bgTask = UIBackgroundTaskInvalid;}];      // Start the long-running task and return immediately.      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),   ^{          // Do the work associated with the task, preferably in chunks.<span style="font-family: Arial, Helvetica, sans-serif;">//如果要提前结束:</span><span style="color: rgb(68, 68, 68); font-family: Menlo; font-size: 10pt;">application</span><span style="color: rgb(68, 68, 68); font-size: 10pt; font-family: Menlo;">.backgroundTimeRemaining </span>
          [application endBackgroundTask:bgTask];          bgTask = UIBackgroundTaskInvalid;      });}

0 0
原创粉丝点击