iPhone 应用程序退出前使会话失效

发布于 2024-08-27 13:41:34 字数 349 浏览 4 评论 0原文

我想告诉服务器当用户退出 iPhone 应用程序时使正在进行的会话无效。

在应用程序委托中,我在 (void)applicationWillTerminate:(UIApplication *)application 方法中向服务器发送请求。我不是在等待服务器答复,我只想发送请求并退出。

但是我看不到任何数据包离开应用程序。相同的代码在另一个地方工作正常。

无论如何,会话的持续时间有限,服务器会在一段时间后使其失效,但我更愿意在离开应用程序时做得很好。

从 applicationWillTerminate 方法中无法建立 NSURLConnection 是否正常?

谢谢。

I would like to tell the server to invalidate an ongoing session when the user quits the iPhone application.

In the app delegate, I send a request to the server in the (void)applicationWillTerminate:(UIApplication *)application method. I am not waiting for a server answer, I just want to send the request and quit.

However I cant see any packet leaving the application. The same code in another place works fine.

Session has a limited duration anyway and the server will invalidate it after a while, but I would prefer to do it nicely when leaving application.

Is it normal that no NSURLConnection can be established from the applicationWillTerminate method ?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

黒涩兲箜 2024-09-03 13:41:35

如果您发送异步请求,则应用程序很可能在发出请求之前退出。

尝试使用同步请求作为测试,但我不建议在生产中这样做,因为同步请求可能需要不确定的时间。如果他的应用程序强行退出,它会在 iTunes Connect 的崩溃报告部分显示为“退出超时”。

If you're sending an asynchronous request, it's very likely that the app quits before the request is made.

Try using a synchronous request as a test, although I wouldn't recommend doing that in production, as synchronous requests can take an indeterminate amount of time. If he app forcibly quits, it'll show as a "time-out on quit" in your crash reports section in iTunes Connect.

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