如何终止 iPhone 中的 API 调用
我是 iPhone 新手。我遇到了一个新问题。我的应用程序中有一个 API 交互。该 API 需要很长时间才能加载。当我手动终止我的应用程序并加载该 API 时,我的应用程序关闭了。然后我会打开我的应用程序,它会立即关闭。
任何人都可以帮助我如何在取消 API 调用时终止或终止它?
I am new to iPhone. I have faced a new problem. I have an API interaction in my app. That API take long time for loading. When I terminate my app manually, while loading that API my app closed. Then I would open my app it will closed immediately.
Can any one help me how can I terminate or kill the API call while cancel it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你指的是网络 API 调用,比如谷歌的地理服务。为此,您需要使用 NSURLConnection 进行调用。这样,您就可以随时使用[连接取消]取消通话。
尝试这个教程: http://mobileorchard.com/tutorial-json- over-http-on-the-iphone/ 它用于 JSON api 调用。如果您需要另一个 API,只需从“通过 HTTP 获取 JSON”开始阅读,他们在那里设置了 NSURLConnection。如果您保留此连接直到完成,您将可以随时拨打[连接取消]呼叫。
使用UIApplicationDelegate,您可以检测进入后台的应用程序。
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: http://mobileorchard.com/tutorial-json-over-http-on-the-iphone/ 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.