如何终止 iPhone 中的 API 调用

发布于 2024-10-24 01:06:38 字数 155 浏览 3 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老子叫无熙 2024-10-31 01:06:38

我想你指的是网络 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文