There are a few key points to note when writing iOS clients using the rest service:
- Never use synchronous network calls. even in a background thread, the synchronization call does not report progress. Another reason is that if you want to cancel a synchronization request for a background thread, you can only end this thread, which is also not a good idea. In addition, there is no control over the number of network requests in the application, which is critical to the performance of the application.
- Try not to use Nsthread or GCD-based threads for network operations (unless the project is very small and there are only a few API calls).
- use a nsoperationqueue-based thread. with Nsoperationqueue, you can control the queue length and the number of concurrent network operations very well. GCD-based threads cannot be canceled after the block has been dispatched.
Reference documents:
Rob Napier is waiting, the American Regiment mobile translation. iOS programming combat. BEIJING, People's post and telecommunications press. Page 161
IOS 8:rest Programming several considerations