문제

NSOperation을 생성하고 NSURLConnections를 동시에 열어 서버로 백엔드 데이터로드를 구현하고 있습니다.

이 코드는 주 스레드로 돌아갈 알림이있는 진행률 표시 줄을 추가 할 때까지 시뮬레이터와 장치 모두에서 완벽하게 작동했습니다.

- (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으로 갑자기 잘못한 일을 해결하려고 노력하고 있습니다.

모든 도움이 감사합니다!

도움이 되었습니까?

해결책 2

이 질문을 개발자 포럼에도 게시했으며 동시성을 제거하라는 제안을 받았습니다. 나는 불쾌한 선을 제거했다 :

[NSThread detachNewThreadSelector:@selector(main ) toTarget:selfwithObject:nil];

나는 또한 시작을 재정의하지 않았고 Main을 무시했습니다.

nsurlconnection은 충돌이 중단되었습니다.

다른 팁

나는 당신의 문제가 무엇인지 정확히 알지 못하지만, 나는 nsurlconnection을 사용할 때 무작위 오류와 충돌을 일으켰다는 것을 알고 있습니다. 그런 다음 찾았습니다 Asihttprequest 그리고 결코 뒤돌아 보지 않았습니다. NSURLConnection의 교체가 줄어들고 CFNetwork에서 실행됩니다. 그것은 매우 안정적이며 (모든 프로젝트에서 사용합니다) 내장 진행 상황 바 지원 및 부분 다운로드 소비와 같은 많은 음식이 제공됩니다. iPhone에서 중요한 RAM을 저장하기 위해 디스크에 직접 쓸 수도 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top