Does AFNetworking have backgrounding support?

前端 未结 1 1593
-上瘾入骨i
-上瘾入骨i 2020-11-28 05:37

I\'m in the process of investigating AFNetworking as a replacement for ASIHTTPRequest, and notice a complete lack of information on whether it supp

相关标签:
1条回答
  • 2020-11-28 05:44

    EDIT: As of AFNetworking 1.0RC1, this is an explicit feature. AFURLConnectionOperation now has the method setShouldExecuteAsBackgroundTaskWithExpirationHandler:, which transparently manages all of this for you.


    It's an implicit feature, so I didn't really think about advertising it. All you'd need to do is:

    
    - (void)applicationWillResignActive:(UIApplication *)application {
        __block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^(void) {
            [application endBackgroundTask:backgroundTaskIdentifier];
            [[YourRestClient sharedClient] cancelAllHTTPOperations];
        }];
    }
    
    

    Or, if you manage your operations in your own NSOperationQueue, just -cancelAllOperations here instead.

    0 讨论(0)
提交回复
热议问题