我有一个名为writeToServer
的静态方法,当应用程序进入后台模式时调用。
在AppDelegate.m
:
- (void)applicationDidEnterBackground:(UIApplication *) application {
[LogZone writeToServer];
NSLog(@"Log sended to server. Done.");
}
在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];
}
大写变量是以这种方式创建的静态字符串:
·H
extern NSString* _LOG_UID;
的.m
NSString* _LOG_UID = @"-1";
当我进入后台模式时,它会因“经典”错误而崩溃:
* - [CFString respondsToSelector:]:发送到解除分配的实例的消息 0x6a4c800
但为什么呢? 我不发布任何内容!=!
怎么了?
答案 0 :(得分:1)
但为什么呢? 我不发布任何内容!
当然,但你保留了正确的物品吗?
在正确的时间保留与在错误的时间不释放一样重要......
答案 1 :(得分:-1)
为什么不使用以下内容:
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];