AFNetworking和 - [__ NSCFBoolean length]:无法识别的选择器发送到实例0x1f54358

时间:2014-03-24 15:00:10

标签: ios objective-c static-libraries afnetworking unrecognized-selector

我现在有几天这个奇怪的问题2014-03-24 16:50:56.097 MyApp[1610:4703] -[__NSCFBoolean length]: unrecognized selector sent to instance 0x1f54358

我已经调试了我的库,这是一个静态库,我将其打包为.framework并分发给开发人员。

从断点来看,调试有点难,所以我将静态库.xcodeproj文件添加到示例客户端应用程序并尝试使用它。经过一些研究并试图弄清楚这种情况发生的原因我没有别的理由认为它是AFNetworking的问题!

我在静态库中有这段代码:

编辑:

// Selector parameter (NSData *)theData

    NSMutableURLRequest *aRequest = [[[NSMutableURLRequest alloc] initWithURL:theURL                                                                              cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0f] autorelease];

            [aRequest setHTTPMethod:@"POST"];
            [aRequest setValue:key forHTTPHeaderField:@"Custom-Header"];
            [aRequest setValue:@"plain/text" forHTTPHeaderField:@"Content-Type"];

    NSMutableData *postData = [NSMutableData data];
            [postData appendData:theData];
            [aRequest setHTTPBody:postData];

    AFHTTPRequestOperation* operation = [[AFHTTPRequestOperation alloc] initWithRequest:aRequest];

                [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
                    {
                    _pendingDispatchesCount --;
                    NSLog(@"%@, %ld", kServerRespondedMsg, (long)operation.response.statusCode);
                    BOOL statusCodeAcceptable = [[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)] containsIndex:[operation.response statusCode]];
                    dispatch_async(dispatch_get_main_queue(),
                        ^{
                            [delegate analyticsOperationCompleted:statusCodeAcceptable forData:analyticsData];
                        });
                    }
                failure:^(AFHTTPRequestOperation *operation, NSError *error)
                    {
                    _pendingDispatchesCount --;
                    NSLog(@"%@, %ld", kServerRespondedMsg, (long)operation.response.statusCode);
                    dispatch_async(dispatch_get_main_queue(),
                        ^{
                            [delegate analyticsOperationCompleted:NO forData:analyticsData];
                        });
                    }];

                [operation start];

如果我只是评论[operation start];示例客户端正常启动。如果我让操作开始,我会得到2014-03-24 16:50:56.097 MyApp[1610:4703] -[__NSCFBoolean length]: unrecognized selector sent to instance

此刻让我发疯,因为这个错误仅发生在他报告的一个开发人员身上,他实际上创建了一个再现它的样本。

修改 找到了一种获取堆栈跟踪的方法,似乎这不是由我的应用程序引起的:

回溯:

0   CoreFoundation                      0x000000010201c495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000101d7b99e objc_exception_throw + 43
    2   CoreFoundation                      0x00000001020ad65d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010200dd8d ___forwarding___ + 973
    4   CoreFoundation                      0x000000010200d938 _CF_forwarding_prep_0 + 120
    5   CoreFoundation                      0x000000010200e9d1 CFURLCreateStringByAddingPercentEscapes + 81
    6   CFNetwork                           0x0000000103fdf1ab _ZL13appendEscapedP10__CFStringPKS_ + 40
    7   CFNetwork                           0x0000000103fdef69 _ZL25initializeUserAgentStringv + 124
    8   libsystem_pthread.dylib             0x00000001026d58d6 __pthread_once_handler + 65
    9   libsystem_platform.dylib            0x00000001025e3156 _os_once + 73
    10  libsystem_pthread.dylib             0x00000001026d5875 pthread_once + 57
    11  CFNetwork                           0x0000000103fdeb23 cleanUpRequest + 105
    12  CFNetwork                           0x0000000103fde824 _ZN17HTTPNetConnection19prepareTransmissionEP17HTTPNetStreamInfoP17__CoreWriteStream + 1224
    13  CFNetwork                           0x0000000103fdda65 _ZN13NetConnection7enqueueEPvh + 539
    14  CFNetwork                           0x0000000103fdd7e4 _ZN17HTTPNetStreamInfo16_streamImpl_OpenEP13CFStreamErrorPh + 88
    15  CFNetwork                           0x000000010403c295 _ZThn120_N17HTTPNetStreamInfo16_streamImpl_OpenEP13CFStreamErrorPh + 13
    16  CFNetwork                           0x0000000103fbdfc2 _ZN14CoreStreamBase21_streamInterface_OpenEv + 80
    17  CFNetwork                           0x0000000103fdd057 _ZN12HTTPProtocol10openStreamEv + 255
    18  CFNetwork                           0x0000000104048c41 _ZN12HTTPProtocol26useNetConnectionForRequestEP13NetConnectionP15__CFHTTPMessageh + 1753
    19  CFNetwork                           0x0000000103fdc268 _ZN24HTTPConnectionCacheEntry28dispatchConnectionToProtocolEP13NetConnectionP12HTTPProtocolP18HTTPRequestMessageh + 276
    20  CFNetwork                           0x0000000103fdc027 _ZN24HTTPConnectionCacheEntry34notifyNextProtocolOfOpenConnectionEP13NetConnectionh + 301
    21  CFNetwork                           0x0000000103fd9230 _ZN24HTTPConnectionCacheEntry25enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage + 650
    22  CFNetwork                           0x0000000103fd8bf0 _ZN19HTTPConnectionCache34_onqueue_enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage + 178
    23  CFNetwork                           0x000000010404e843 ___ZN19HTTPConnectionCache25enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage_block_invoke + 26
    24  CoreFoundation                      0x0000000101fc2f74 CFArrayApplyFunction + 68
    25  CFNetwork                           0x0000000103fd43e7 _ZN19RunloopBlockContext7performEv + 133
    26  CFNetwork                           0x0000000103fd4217 _ZN17MultiplexerSource7performEv + 247
    27  CFNetwork                           0x0000000103fd403a _ZN17MultiplexerSource8_performEPv + 72
    28  CoreFoundation                      0x0000000101fabd21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    29  CoreFoundation                      0x0000000101fab5f2 __CFRunLoopDoSources0 + 242
    30  CoreFoundation                      0x0000000101fc746f __CFRunLoopRun + 767
    31  CoreFoundation                      0x0000000101fc6d83 CFRunLoopRunSpecific + 467
    32  Foundation                          0x000000010193089c +[NSURLConnection(Loader) _resourceLoadLoop:] + 348
    33  Foundation                          0x00000001019832df __NSThread__main__ + 1167
    34  libsystem_pthread.dylib             0x00000001026d4899 _pthread_body + 138
    35  libsystem_pthread.dylib             0x00000001026d472a _pthread_struct_init + 0
    36  libsystem_pthread.dylib             0x00000001026d8fc9 thread_start + 13

编辑: 链接完整的PLCrashReporter崩溃报告符号。 https://drive.google.com/file/d/0B_4YDWJioTI1c0hia25NSXFTWVk/edit?usp=sharing

提前感谢任何帮助或想法。

问候。

1 个答案:

答案 0 :(得分:2)

查看堆栈跟踪并考虑可能发生的事情。堆栈跟踪不是一些神奇的东西,它与您的代码直接相关。

崩溃是由有人向包含NSNumber值的Boolean发送“长度”消息引起的。

在堆栈跟踪中,我们看到CFURLCreateStringByAddingPercentEscapes。所以似乎用CFURLCreateStringByAddingPercentEscapes对象而不是字符串调用NSNumber

为什么要调用CFURLCreateStringByAddingPercentEscapes?它通常被称为包含U​​RL和类似事物的字符串,这些字符串不能按原样传输并且需要翻译,例如空格到%20。

因此,您可能会将NSNumber传递给将通过网络发送的内容。像标题属性一样,URL,等等。

完成您在URL请求中设置的所有内容。问题可能出在“aRequest”中,特别是因为你决定隐藏它。 (那是潜意识,不想让我们看到你的错误,这当然会适得其反)。