Afnetworking: -[__NSCFNumber length]: unrecognized selector sent to instance

Created on 3 Mar 2017  ·  5Comments  ·  Source: AFNetworking/AFNetworking

I use this method to post a request and get this crash:

NSDictionary *requestProto = @{
@"d":@{
@"phone":@"a18611787914",
}
};

MyLog(@"requestProto = %@", requestProto);

[manager POST:baseRequest.url parameters:requestProto progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    [baseResponse setHttpResponse:responseObject];
    MyLog(@"responseObject = %@", responseObject);
    /*业务成功*/
    [self notifyResponse : baseRequest];

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    /*业务失败,可能是网络、客户端或后台任何一方存在问题*/
    [self notifyResponseError : baseRequest];
    MyLog(@"responseError = %@", error);

}];

017-03-03 10:05:02.302 Bigu[74253:248721] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb00000000989b933'
*
First throw call stack:
(
0 CoreFoundation 0x0000000111e97d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000011156721e objc_exception_throw + 48
2 CoreFoundation 0x0000000111f07f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000111e1d005 ___forwarding___ + 1013
4 CoreFoundation 0x0000000111e1cb88 _CF_forwarding_prep_0 + 120
5 CFNetwork 0x0000000113d2c731 _ZN15HTTPHeaderValue7isValidEPK10__CFString + 19
6 CFNetwork 0x0000000113d2c68d _ZN11HTTPMessage25setHeaderFieldStringValueEPK10__CFStringS2_ + 41
7 CFNetwork 0x0000000113d2bfe6 CFURLRequestSetHTTPHeaderFieldValue + 133
8 Bigu 0x000000010e93f2c3 __76-[AFJSONRequestSerializer requestBySerializingRequest:withParameters:error:]_block_invoke + 227
9 CoreFoundation 0x0000000111e282a5 __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 85
10 CoreFoundation 0x0000000111e281ba -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] + 250
11 Bigu 0x000000010e93ee36 -[AFJSONRequestSerializer requestBySerializingRequest:withParameters:error:] + 918
12 Bigu 0x000000010e93531b -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:] + 1963
13 Bigu 0x000000010e9efe2f -[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:uploadProgress:downloadProgress:success:failure:] + 511
14 Bigu 0x000000010e9eeb2d -[AFHTTPSessionManager POST:parameters:progress:success:failure:] + 253
15 Bigu 0x000000010e8a4048 -[RequestManager startTask] + 1992
16 Bigu 0x000000010e8a3853 -[RequestManager doTaskRequest:response:] + 147
17 Bigu 0x000000010e8ef977 -[BaseRequest doRequest] + 135
18 Bigu 0x000000010e99fc06 -[RegisterViewController submit4Code] + 294
19 Bigu 0x000000010e99f58b -[RegisterViewController checkPhoneAndSubmit:] + 1451
20 UIKit 0x000000010fab48bc -[UIApplication sendAction:to:from:forEvent:] + 83
21 UIKit 0x000000010fc3ac38 -[UIControl sendAction:to:forEvent:] + 67
22 UIKit 0x000000010fc3af51 -[UIControl _sendActionsForEvents:withEvent:] + 444
23 UIKit 0x000000010fc39e4d -[UIControl touchesEnded:withEvent:] + 668
24 UIKit 0x000000010fb22545 -[UIWindow _sendTouchesForEvent:] + 2747
25 UIKit 0x000000010fb23c33 -[UIWindow sendEvent:] + 4011
26 UIKit 0x000000010fad09ab -[UIApplication sendEvent:] + 371
27 UIKit 0x00000001102bd72d __dispatchPreprocessedEventFromEventQueue + 3248
28 UIKit 0x00000001102b6463 __handleEventQueue + 4879
29 CoreFoundation 0x0000000111e3c761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
30 CoreFoundation 0x0000000111e2198c __CFRunLoopDoSources0 + 556
31 CoreFoundation 0x0000000111e20e76 __CFRunLoopRun + 918
32 CoreFoundation 0x0000000111e20884 CFRunLoopRunSpecific + 420
33 GraphicsServices 0x0000000115e8ba6f GSEventRunModal + 161
34 UIKit 0x000000010fab2c68 UIApplicationMain + 159
35 Bigu 0x000000010e9705ff main + 111
36 libdyld.dylib 0x000000011481c68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

All 5 comments

and our server doesnt receive the post request.

You sure that's what you're sending? The crash log says [__NSCFNumber length]. That's a NSNumber, not a NSString.

Tewha,

I'm getting this error, could you please take a look?

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:uploadProgress:downloadProgress:success:failure:]: unrecognized selector sent to instance 0x7b497620'

编译器都告诉你什么错误了,明显类型不匹配!不是AF的问题,是你解析数据有问题

Looking at these lines immediately before the crash:

5 CFNetwork 0x0000000113d2c731 _ZN15HTTPHeaderValue7isValidEPK10__CFString + 19
6 CFNetwork 0x0000000113d2c68d ZN11HTTPMessage25setHeaderFieldStringValueEPK10__CFStringS2 + 41
7 CFNetwork 0x0000000113d2bfe6 CFURLRequestSetHTTPHeaderFieldValue + 133

It looks to me like you are setting something as the value for an HTTP header that isn't a string.

Was this page helpful?
0 / 5 - 0 ratings