Search code examples
iphonesessioninvalidationquit

Invalidating session before iPhone application quits


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.


Solution

  • 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.