UIBackgroundTaskIdentifier bgTask; 把即将退出到后台的程序恢复

来源:互联网 发布:mmd镜头数据下载 编辑:程序博客网 时间:2024/06/05 10:16

这段代码可以放在

- (void)applicationWillResignActive:(UIApplication *)application

或者 - (void)applicationDidEnterBackground:(UIApplication *)application    中


bgTask = [applicationbeginBackgroundTaskWithExpirationHandler:^{

       // 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.

        [application endBackgroundTask:bgTask];

        bgTask =UIBackgroundTaskInvalid;

  });

0 0
原创粉丝点击