views:

274

answers:

3

Hi ,

I am trying to post some data before my application terminates. Iam doing this by genrateing sockets using CFStreamCreatePairWithSocketToCFHost and later on I have the callbacks for reading and writing.

But I am not able to post any data. It goes through all the functions but doesnot enter into callbacks. Does that make sense to anyone?. Is there anyway to get this working?

Thanks, Sowri

A: 

My gut feeling is that after the applicationWillTerminate method is done, it will just stop the whole app, without giving any other run loop the chance to execute, let alone do callbacks. So my guess is that calling asynchronous methods in the applicationWillTerminate won't even start. You're just too late at that point to start networking.

drvdijk
Thanks, I got rid of the call backs and used NSURL connection to post
Sowri
+1  A: 

Yes, after applicationWillTerminate is called, there are no more iterations of the run loop. Since CFSocket and CFStream both use the run loop to manage the sockets and to provide data via the callback, this will not work. Also, it's very important to note that the application may be restricted from doing certain things at this stage and that if your application does not terminate, the operating system will terminate the application. It may be a better idea to write a small log to a database and then post that information back the next time the application starts.

Jason Coco
Thanks, That helps
Sowri
A: 

The applicationWillTerminate: callback is not the place to do any kind of critical operation because as the name implies, your application will terminate and it won't wait for your code to finish doing something.

What are you trying to post; if you explain why you want to do this we may be able to offer a better solution.

Luke Redpath
thanks , I was just trying to log the user actions in the server by posting that data when the application terminates. I guess I can just do it with NSURL Connection.
Sowri