开发者

applicationWillTerminate didn't call

i try to use applicationWillTerminate in my app and i want that in this function i will send data to server,with this:

reqURL = [reqURL stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURLRequest *theReque开发者_如何学Gost = [NSURLRequest requestWithURL:[NSURL URLWithString:reqURL]];
NSURLResponse *resp = nil;
NSError *err = nil;
NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &resp error: &err];

but the problem is that this function didn't call when i close my app.


In iOS 4.x, apps are often moved into the background (in order to be quickly resumed) as opposed to being purged from memory. applicationWillTerminate: is only called when the latter occurs. You probably want applicationDidEnterBackground: which will be called when your app is quit but continues to stick around in the background. You will only have about 5 seconds to do any clean-up so you may also want to look into the beginBackgroundTaskWithExpirationHandler: / endBackgroundTask: methods in case your request is of critical importance and possibly requires more time.


Most likely the application will be going into the background state, not exiting completely. Try putting your code into:

- (void)applicationWillResignActive:(UIApplication *)application;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜