iPhone应用程序崩溃[NSObject(NSObject)doesNotRecognizeSelector:]

时间:2013-10-21 12:36:41

标签: iphone ios afnetworking

这是崩溃报告不确定原因。我使用AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:进行调用。在完成块中,我得到结果并将其传递给我的数据模型上的类别类,以插入到核心数据表中。

下面的

是崩溃日志..

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

请给我一些关于崩溃日志的见解。我已经在这几个小时了。

这是我的代码..

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];

[BTRooms createNewRoom:room withNode:@“”]看起来像这样..

+ (BTRooms*) createNewRoom:(NSDictionary *)roomDic withNode: (NSString*) node{
    NSString* roomId = [roomDic objectForKey:@"roomid"];
//more code here
}

使用xCode连接和调试时不会崩溃。当应用程序在后台运行一段时间后,它会随机崩溃,我会在设备中运行它。进行远程调用的是我的tabbar控制器viewcontroller。

NEW UPDATE

想出来!对于误导性问题,我们深表歉意。与iOS无关。这是服务器端的一个错误(应用程序引擎问题)。我将在另一个问题中发布。

[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!!
}

1 个答案:

答案 0 :(得分:5)

检查代码崩溃位置的好方法是:

  1. 转到Xcode中的断点选项卡。
  2. 点击底部的“+”按钮。
  3. 添加异常断点
    • 在中断选项卡中,选择:Throw和on Catch,以及构建和运行。
  4. 这些断点会准确地为您提供应用程序在90%的时间内崩溃的位置。
  5. 希望这有助于你