Reputation: 146
Here is the crash report not sure why. I use AFHTTPRequestOperation setCompletionBlockWithSuccess:failure: to make a call. in the completion block I get the results and pass it to a category class on my data model to insert into core data tables.
below is the crash log..
Last Exception Backtrace:
0 CoreFoundation 0x2fed7f4e __exceptionPreprocess + 126
1 libobjc.A.dylib 0x3a2b06aa objc_exception_throw + 34
2 CoreFoundation 0x2fedb8e2 -[NSObject(NSObject) doesNotRecognizeSelector:] + 198
3 CoreFoundation 0x2feda1ce ___forwarding___ + 702
4 CoreFoundation 0x2fe29594 __forwarding_prep_0___ + 20
5 <myappname> 0x000bbfe8 +[BTRooms(Data) createNewRoom:withNode:] (BTRooms+Data.m:32)
6 <myappname> 0x000b034e __28-[BTNet createRoom:friends:]_block_invoke (BTNet.m:551)
7 <myappname> 0x0008fd10 __64-[AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke139 (AFHTTPRequestOperation.m:279)
8 libdispatch.dylib 0x3a793d76 _dispatch_call_block_and_release + 6
9 libdispatch.dylib 0x3a793d62 _dispatch_client_callout + 18
10 libdispatch.dylib 0x3a79a7bc _dispatch_main_queue_callback_4CF$VARIANT$mp + 264
11 CoreFoundation 0x2fea281c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
12 CoreFoundation 0x2fea10f0 __CFRunLoopRun + 1296
13 CoreFoundation 0x2fe0bce2 CFRunLoopRunSpecific + 518
14 CoreFoundation 0x2fe0bac6 CFRunLoopRunInMode + 102
15 GraphicsServices 0x34b2c27e GSEventRunModal + 134
16 UIKit 0x326ada3c UIApplicationMain + 1132
17 <myappname> 0x0005e280 main (main.m:16)
18 libdyld.dylib 0x3a7b8ab2 tlv_initializer + 2
Crashed Thread
0 libsystem_kernel.dylib 0x3a86f1fc __pthread_kill + 8
1 libsystem_pthread.dylib 0x3a8d8a2e pthread_kill + 54
2 libsystem_c.dylib 0x3a81fff8 abort + 72
3 libc++abi.dylib 0x39b4ecd2 abort_message + 70
4 libc++abi.dylib 0x39b676e0 default_terminate_handler() + 248
5 libobjc.A.dylib 0x3a2b091e _objc_terminate() + 190
6 libc++abi.dylib 0x39b651c4 std::__terminate(void (*)()) + 76
7 libc++abi.dylib 0x39b64a18 __cxa_throw + 112
8 libobjc.A.dylib 0x3a2b077e objc_exception_throw + 246
9 CoreFoundation 0x2fedb8e2 -[NSObject(NSObject) doesNotRecognizeSelector:] + 198
10 CoreFoundation 0x2feda1ce ___forwarding___ + 702
11 CoreFoundation 0x2fe29594 __forwarding_prep_0___ + 20
12 <myappname> 0x000bbfea +[BTRooms(Data) createNewRoom:withNode:] (BTRooms+Data.m:32)
13 <myappname> 0x000b0350 __28-[BTNet createRoom:friends:]_block_invoke (BTNet.m:551)
14 <myappname> 0x0008fd12 __64-[AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke139 (AFHTTPRequestOperation.m:279)
15 libdispatch.dylib 0x3a793d78 _dispatch_call_block_and_release + 8
16 libdispatch.dylib 0x3a793d64 _dispatch_client_callout + 20
17 libdispatch.dylib 0x3a79a7bc _dispatch_main_queue_callback_4CF$VARIANT$mp + 264
18 CoreFoundation 0x2fea281c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
19 CoreFoundation 0x2fea10f0 __CFRunLoopRun + 1296
20 CoreFoundation 0x2fe0bce2 CFRunLoopRunSpecific + 518
21 CoreFoundation 0x2fe0bac6 CFRunLoopRunInMode + 102
22 GraphicsServices 0x34b2c27e GSEventRunModal + 134
23 UIKit 0x326ada3c UIApplicationMain + 1132
24 <myappname> 0x0005e280 main (main.m:16)
25 libdyld.dylib 0x3a7b8ab4 start + 0
Please give me some insights on the crash log. I have been on this for several hours now.
Here is my code..
MyClient* client = [MyClient sharedClient];
[client setParameterEncoding:AFJSONParameterEncoding];
NSMutableURLRequest* request = [client requestWithMethod:@"POST" path:@"/JoinRoom" parameters:data];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[client registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// Print the response body in text
//NSString* responseText = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSError* error3;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseObject //1
options:0
error:&error3];
NSString* status = [json objectForKey:@"status"];
if ([status isEqualToString:kBTOK]){ // OK
NSDictionary* room = [json objectForKey:@"data"];
BTRooms* newRoom = [BTRooms createNewRoom:room withNode:@""];
}
else{
// Do something else
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// Do something else
}];
[[[MyClient sharedClient] operationQueue] addOperation:operation];
And [BTRooms createNewRoom:room withNode:@""] looks like this..
+ (BTRooms*) createNewRoom:(NSDictionary *)roomDic withNode: (NSString*) node{
NSString* roomId = [roomDic objectForKey:@"roomid"];
//more code here
}
It doesn't crash when I connect and debug with xCode. It crashes randomly when the app is in the background for a while and I run it in the device. The one that made the remote call is one of my tabbar controller viewcontroller.
NEW UPDATE:
Figured it out! Sorry for the misleading question. nothing to do with iOS. it was a bug from the server side (app engine issue). I will post that in a separate question.
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError* error3;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseObject //1
options:0
error:&error3];
NSString* status = [json objectForKey:@"status"];
if ([status isEqualToString:kBTOK]){ // OK
NSDictionary* room = [json objectForKey:@"data"];
// room is null here!!
}
Upvotes: 1
Views: 4748
Reputation: 171
A good way to check where your code is crashing is:
Hope this helps you
Upvotes: 5