Why my application crash on applicationDidEnterBackground?
I have a static method called writeToServer
that is called when application enter in background mode.
in my AppDelegate.m
:
- (void)applicationDidEnterBackground:(UIApplication *) application {
[LogZone writeToServer];
NSLog(@"Log sended to server. Done.");
}
in my LogZone.m
:
+ (void) writeToServer {
NSString *qStr = [[NSString alloc]
initWithFormat:@"%@?ip=%@&uid=%@&platform=%@&model=%@&lat=%@&lon=%@",
LOG_SERVER_URL,
_LOG_IP, _LOG_UID, _LOG_PLAT, _LOG_MOD, _LOG_LAT, _LOG_LON];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:qStr]];
[request setHTTPMethod: @"POST"];
[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
}
Uppercase vars are static strings created in this way:
.h
extern NSString* _LOG_UID;
NSString* _LOG_UID = @"-1";
When I enter in background mode it crash with this "classic" error:
* -[CFString respondsToSelector:]: message sent to deallocated instance 0x6a4c800
But why?
I don't release anything!=!What's wrong?
But why? I don't release anything!
Sure, but do you retain the right objects?
Retaining at the right time is every bit as important as not releasing at the wrong time...
Why not just use the following:
NSString *qStr = [NSString stringWithFormat:@"%@?ip=%@&uid=%@&platform=%@&model=%@&lat=%@&lon=%@", LOG_SERVER_URL, _LOG_IP, _LOG_UID, _LOG_PLAT, _LOG_MOD, _LOG_LAT, _LOG_LON];
精彩评论