Search code examples
iosmultithreadingnetwork-programmingnsoperationwsdl2objc

Asynchronus operation inside NSOperation


I have a web service, which I'm using to upload images to a server. I consume the service inside an NSOperation. When I call the methods of service synchronously, everything is ok, but when I call the methods asynchronously, the web server never receives the request. The only reason I can think of this happening is that thread was killed even though inside the web service asynchronous call there is loop which keeps the current runloop active until a response is received.


Solution

  • Looking at the documentation for NSOperation, you will see how to implement concurrent NSOperations. In short, instead of implementing main, you implement start, isConcurrent, isExecuting, and isFinished. So typically you would return YES for isConcurrent, start your request in the start method and set isExecuting to YES, and when your request finishes set isFinished to YES. For much more details please see the official Apple NSOperation class documents.