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 で突然何が間違っていたのかを理解しようとしてきました。
どんな助けでも大歓迎です!