开发者

how to terminate api call in iphone [duplicate]

This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

how can i terminate api call in iphone

hi friends,

I have an api call in my iphone app. That api call take more ti开发者_如何学运维me for loading (near 100 sec). while the api processing, i hit the home button of my app. the app terminated. but the api call doesn't terminated.

how can I terminate api call.


Like e.James said, look at the UIApplicationDelegate protocol.

However, you might be more interested in either applicationDidEnterBackground: or applicationWillTerminate: (depending on whether or not the device supports multitasking), because applicationWillResignActive: will also be called in cases like when the user receives a phone call, or other similar interruptions (see documentation).


Check out the UIApplicationDelegate protocol. You can cancel the API call in the applicationWillResignActive: method, which is called just before the app goes into background mode.


Seeing you duped the question, i'll post my answer here too:

I suppose you mean a web API call, like google's geoservices. To do this, you will need to make the call using a NSURLConnection. This way, you can cancel a call anytime using [connection cancel].

Try this tutorial. It's meant for a JSON api call. If you need another API, just start reading from 'fetching JSON over HTTP', there they set up a NSURLConnection. If you retain this connection until it's done, you will be able to make the [connection cancel] call at anytime.

Using the UIApplicationDelegate, you can detect the app entering the background.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜