内applicationDidEnterBackground方法我的程序收到错误信号“EXC_BAD_ACCESS”错误。在[self goingOffline]上;线问题代理线程1:程序收到坏信号“EXC_BAD_ACCESS”
-(void)goingOffline
{
NSLog(@"going offline");
profileViewController * theController;
NSArray * viewControllers = rootController.viewControllers;
for (UIViewController * viewController in viewControllers) {
if ([viewController isMemberOfClass:[profileViewController class]]) {
theController = (profileViewController *)viewController;;
}
}
NSString *userID = theController.userId;
NSMutableData *data = [NSMutableData data];
NSMutableString *userString = [[NSMutableString alloc] initWithFormat:@"id=%@", userID];
//NSLog(userString);
//NSLog(numberString);
[data appendData:[userString dataUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:@"http://www.blah.net/offline.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
[userID release];
[data release];
[request release];
[url release];
[userString release];
[response release];
[err release];
[responseData release];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
[self goingOffline];
}
你怎么知道是否有东西是自动释放的,因为在我的代码中没有引用它。 – mintuz
无论未分配,复制,保留还是新增,都是自动释放 – Julien
像[NSURL URLWithString:@“http://www.blah.net/offline.php”]使用[NSURL URLWithString:]创建一个对象,而URLWithString不包含任何神奇的单词:alloc,retain,new,copy,所以它是自动释放的 – Julien