【发布时间】:2014-01-06 23:50:33
【问题描述】:
我有一个名为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];
}
大写的 var 是以这种方式创建的静态字符串:
.h
extern NSString* _LOG_UID;
.m
NSString* _LOG_UID = @"-1";
当我进入后台模式时,它会因“classic”错误而崩溃:
* -[CFString respondsToSelector:]:消息发送到释放的实例 0x6a4c800
但是为什么呢?
我什么都不发布!=!
怎么了?
【问题讨论】:
-
从调试器发布堆栈跟踪。
-
我做不到。它只显示“2011-01-22 21:02:02.314 myApp[8709:207] *** -[CFString respondsToSelector:]: message sent to deallocated instance 0x6942bf0”在这一行:“NSString *qStr[... ]"
-
注意objective-c没有static方法....
-
我们中间有一位 ARC 开发人员。
标签: iphone objective-c nsurlconnection