2012-09-03 1 views
-1

문제가 있습니다.ios to php EXC_BAD_ACCES 데이터 객체

PHP 파일을 보내야합니다. EXC_BAD_ACCES 만받습니다.

데이터 개체를 릴리스해야 할 수도 있습니다. 하지만 내 데이터 개체가 무엇인지 모르겠습니다.

나는 이것을 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html에서 복사했습니다.

어쩌면 당신은 저를 도울 수 있습니다, 아마 당신을위한 아주 작은 변화지만, 나는 그것을 보지 못합니다.

은 충돌에 대한 자세한 진단 정보를 얻기 위해

NSURL *url = [NSURL URLWithString:@"http://www.yourdomain.com/locatie.php"]; 

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url 
                  cachePolicy:NSURLRequestReloadIgnoringCacheData 
                 timeoutInterval:60]; 

[theRequest setHTTPMethod:@"POST"]; 
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 

NSString *postData = [NSString stringWithFormat:@"longitude=%@&latitude=%@&stringFromDate=%@", longitude, latitude, stringFromDate]; 

NSString *length = [NSString stringWithFormat:@"%d", [postData length]]; 
[theRequest setValue:length forHTTPHeaderField:@"Content-Length"]; 

[theRequest setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]]; 

NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self]; 
[sConnection start]; 

if (sConnection) { 
    // Create the NSMutableData to hold the received data. 
    // receivedData is an instance variable declared elsewhere. 
    theRequest = [[NSMutableData data] retain]; 
} else { 
    // Inform the user that the connection failed. 
} 


} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
// This method is called when the server has determined that it 
// has enough information to create the NSURLResponse. 

// It can be called multiple times, for example in the case of a 
// redirect, so each time we reset the data. 

// receivedData is an instance variable declared elsewhere. 
} 
- (void)connection:(NSURLConnection *)connection 
didFailWithError:(NSError *)error 
{ 
// release the connection, and the data object 
[connection release]; 
// receivedData is declared as a method instance elsewhere 

// inform the user 
NSLog(@"Connection failed! Error - %@ %@", 
     [error localizedDescription], 
     [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
// do something with the data 
// receivedData is declared as a method instance elsewhere 
NSLog(@"Succeeded! Received bytes of data"); 

// release the connection, and the data object 
[connection release]; 
} 
+0

어떤 줄에 EXC_BAD_ACCES가 있습니까? – sergio

+0

그건 내 문제 야. 그 오류를주지 않습니다. 데이터 객체를 해제해야한다고 생각합니다. 나는 데이터 객체 라인을 삭제했다. 왜냐하면 그 객체가 어디에 있는지, 그리고 데이터 객체가 무엇인지 알지 못했기 때문이다. –

답변

0

Enable NSZombies을 접견. 이것은 오브젝트를 과도하게 해제하는 것과 관련이 있습니다.

코드를 보면, 나는 문제가 여기에 있다고 생각 :

NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self]; 

이 (방법의)를이 선언 된 범위의 끝에서 사라질 것 오토 릴리즈 객체입니다.

수정 사항은 클래스의 retain 속성에 NSURLConnection 참조를 저장합니다.