切换到后台 申请长时间运行

DownloadHandler *handler = [DownloadHandler sharedInstance];

        

        __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{

            // Clean up any unfinished task business by marking where you

            // stopped or ending the task outright.

            [handler resignActive];

            

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

            [handler downloadAfterApplicationBecomeActive];

            

            [application endBackgroundTask:bgTask];

            bgTask = UIBackgroundTaskInvalid;

        });

posted @ 2014-08-07 14:41  dzldzl  阅读(232)  评论(0)    收藏  举报