iPhone 应用程序退出前使会话失效
我想告诉服务器当用户退出 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您发送异步请求,则应用程序很可能在发出请求之前退出。
尝试使用同步请求作为测试,但我不建议在生产中这样做,因为同步请求可能需要不确定的时间。如果他的应用程序强行退出,它会在 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.