views:

143

answers:

2

Hello

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.

A: 

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.

Jasarien
[NSURLConnection sendSynchronousRequest:myRequest returningResponse:NULL error:NULL] worked indeed. But I don't know if I should leave it, as per your warning. Maybe the server should handle the session ending after all.
If the server can gracefully handle the case where a user quits the app and relaunches it within a very short period of time, then the server should definitely take care of it. In that case it would be ideal for the server to reassign the session to the client (you could use the client's UDID for this) or to just create a new session on startup and let the old one fade into the ether.
Jasarien
A: 

Hello

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.

jellisha