Iphone 为什么我的应用程序在ApplicationIdentinterBackground上崩溃?

Iphone 为什么我的应用程序在ApplicationIdentinterBackground上崩溃?,iphone,objective-c,nsurlconnection,Iphone,Objective C,Nsurlconnection,我有一个名为writeToServer的静态方法,当应用程序进入后台模式时调用该方法 在myAppDelegate.m中: - (void)applicationDidEnterBackground:(UIApplication *) application { [LogZone writeToServer]; NSLog(@"Log sended to server. Done."); } + (void) writeToServer { NSString *qStr

我有一个名为
writeToServer
的静态方法,当应用程序进入后台模式时调用该方法

在my
AppDelegate.m
中:

- (void)applicationDidEnterBackground:(UIApplication *) application {
    [LogZone writeToServer];
    NSLog(@"Log sended to server. Done.");
}
+ (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];
}
在my
LogZone.m
中:

- (void)applicationDidEnterBackground:(UIApplication *) application {
    [LogZone writeToServer];
    NSLog(@"Log sended to server. Done.");
}
+ (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

m

当我进入后台模式时,它会崩溃,出现以下“经典”错误:

*-[CFString respondsToSelector:]:发送到解除分配实例的消息 0x6a4c800

但是为什么呢?
我不会发布任何东西

怎么了?

但是为什么呢? 我什么都不放

当然可以,但您是否保留了正确的对象


在正确的时间保留与不在错误的时间释放一样重要…

为什么不使用以下方法:

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];

从调试器发布堆栈跟踪。我无法。它只在这一行上显示“2011-01-22 21:02:02.314 myApp[8709:207]***-[CFString respondsToSelector:]:发送到已解除分配实例0x6942bf0的消息:”NSString*qStr[…]”注意objective-c没有静态方法……我们中间有一个ARC开发人员。这与崩溃无关。正如预期的那样。这将解决可能发生的泄漏,但肯定不会导致坠机+1.我解决了在我的VAR中添加一个retain的问题。(_LOG_IP=[[Device getIPAddress]retain];)。很有效,谢谢。太好了。如果需要,我希望您也添加了相应的版本!