Best practice to send a lot of data in background on iOS4 device?

后端 未结 5 1206
南旧
南旧 2020-12-12 23:55

I have an app that needs to send data (using POST) to a server. This function has to be on one of the NavigationController sub-controllers and user should be able to navigat

5条回答
  •  粉色の甜心
    2020-12-13 00:26

    I'd like to support the post that mentions:

    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ 
          [app endBackgroundTask:bgTask]; 
    
          bgTask = UIBackgroundTaskInvalid;
    }];
    

    But also point out that you may want to encapsulate your unit of work in an NSOperation subclass as well. This will make it extremely re-useable and, when combined with NSOperationQueue, automatically handle threading and what not. Then later, when you want to change your code, or have it appear in a different location in your app, it will be trivial to move or edit.

    One note about using the operation queue, is that in this case you will actually want to send a synchronous url request from within the queue. This will let you not have to worry about concurrent operations. Here is the link that you may find helpful:

    http://www.cimgf.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/

提交回复
热议问题