NSOperation을 만들고 NSURLConnections를 동 기적으로 열어 서버에 백엔드 데이터로드를 구현합니다.NSURLConnection 크래킹
이 코드는 주 스레드로 돌아가는 알림이있는 진행률 표시 줄을 추가 할 때까지 시뮬레이터와 장치 모두에서 완벽하게 작동합니다.
- (void)start {
// stop execution if it's cancelled
if([self isCancelled]) {
[self willChangeValueForKey:@"isFinished"];
finished = YES;
[self didChangeValueForKey:@"isFinished"];
return;
}
// If the operation is not canceled, begin executing the task.
[self willChangeValueForKey:@"isExecuting"];
[NSThread detachNewThreadSelector:@selector(main) toTarget:selfwithObject:nil];
executing = YES;
[self didChangeValueForKey:@"isExecuting"];
}
이제 동기 호출에서 EXC_BAD_ACCESS 충돌이 발생합니다. 다음과 같이
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/index.php", rootURL]];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[bodyString dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSError *error = nil;
NSURLResponse *response = nil;
receivedData = [[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error] mutableCopy];
스택 트레이스 실행 :
#0 0x3430debc in objc_msgSend()
#1 0x3136f996 in NSPopAutoreleasePool()
#2 0x31374160 in -[NSAutoreleasePool release]()
#3 0x331a0408 in _UIApplicationHandleEvent()
#4 0x325339c4 in PurpleEventCallback()
#5 0x3147a52a in CFRunLoopRunSpecific()
#6 0x31479c1e in CFRunLoopRunInMode()
#7 0x3314ec08 in -[UIApplication _run]()
#8 0x3314d230 in UIApplicationMain()
#9 0x00002ab0 in main (argc=1, argv=0x2ffff504)
가 NSZombieEnabled으로, 나는
*** -[NSDateComponents release]: message sent to deallocated instance 0x172fd0
내가 연결이 설정되고 있음을 알 수
(서버 로그에보고 및 요청 통과하고있다). NSURLConnection 이전의 NSOperation 코드에는 아무 곳에서나 할당되는 NSDateComponent 객체가 없습니다.저는 갑자기 NSURLConnection을 잘못 이해하여 해결할 수있었습니다.
도움을 주시면 대단히 감사하겠습니다.
ASIHTTPRequest를 사용해 보았는데 응답 데이터의 압축을 풀 때 오류가 발생했습니다. NSURLConnection은 절대로 발생하지 않았습니다. – serpah