위로 올라가는 ViewController가 있습니다. "저장"을 클릭하면 서버에 요청이 전송됩니다. 요청이 완료되면 ViewController를 닫습니다. 비동기 및 블록 (https://github.com/rickerbh/NSURLConnection-Blocks)을 사용하여 NSURLConnection을 전환했습니다. 이제 ViewController를 닫으면 "스레드 2 : 프로그램 수신 신호 : EXC_BAD_ACCESS"가 발생합니다. 그게 중요하다면 ARC를 사용하고 있습니다.exc_bad_access when dismissViewControllerAnimated를 호출 할 때
- (IBAction) savePressed
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.com/items/create"]];
//NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[NSURLConnection asyncRequest:request success:^(NSData *data, NSURLResponse *response) {
[self close];
} failure:^(NSData *data, NSError *error) {
[self close];
}];
}
- (void) close
{
[self dismissViewControllerAnimated:YES completion:nil];
}
여기에 나는이에 대한 도움말을 검색 2 시간 보냈다
2012-10-24 10:32:43.780 Prayrbox[22268:1703] bool _WebTryThreadLock(bool), 0x1f21fd90: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1 0x347dc927 WebThreadLock
2 0x36718615 <redacted>
3 0x366d0a85 <redacted>
4 0x3678d789 <redacted>
5 0x366c0637 <redacted>
6 0x366d50e7 <redacted>
7 0x368c1f11 <redacted>
8 0x366d4969 <redacted>
9 0x36744745 <redacted>
10 0x366907ad <redacted>
11 0x7ef71 -[ComposeViewController close]
12 0x7eec5 __36-[ComposeViewController savePressed]_block_invoke_0
13 0x82d8f __56+[NSURLConnection(Blocks) asyncRequest:success:failure:]_block_invoke_0
14 0x37e8811f <redacted>
15 0x37e96259 <redacted>
16 0x37e963b9 <redacted>
17 0x37b30a11 <redacted>
18 0x37b308a4 start_wqthread
[Switching to process 10755 thread 0x2a03]
[Switching to process 10755 thread 0x2a03]
[unknown](gdb)
로그입니다. 누구든지 도움이 될 수있는 것이 무엇인지 아는 경우 위로 말하십시오! :)
설명을위한 두 가지 질문 : 1) 완료 핸들러가 주 스레드에서 호출되고 있습니까? 2) NSURLConnection 이미 비동기 요청 메서드가 있습니다 ... 사용하려고 했습니까? 즉, 사용중인 타사 라이브러리에 문제가있는 것일 수 있습니다. – jmstone617
1) 잘 모르겠습니다. 나는 Objective C에 꽤 신선하고 그것을 이해하는 방법을 모른다. 2) 내가 사용하는 카테고리 (게시물의 링크 참조)는 dispatch_async에서 동기 호출을 래핑하고 블록을 제공합니다. 블록을 사용하는 더 좋은 방법이 있다면, 알고 싶습니다. –
첫 번째 질문의 경우 완료 핸들러 내에 중단 점을 설정할 수 있으며 표시되는 스택 추적은 호출되는 스레드를 알려줍니다. (NSURLRequest *) 요청 대기열 : (NSOperationQueue *) 대기열 completionHandler : (void (^) (NSURLResponse *, NSData *, NSError *)) 핸들러는 + (void) sendAsynchronousRequest를 가지고 있습니다. 같은 문제가있어 – jmstone617