为什么这个方法会抛出异常?

时间:2015-10-29 16:19:58

标签: ios iphone appstore-approval

Apple声称我的一种方法是抛出异常,但我无法重现它或找出原因。我收到了一个崩溃日志,它清楚地指出了我在下面发布的方法。很明显,这与访问我的字典有关。但据我所知,这就是。

This is the method in question

- (NSDictionary*)formatUserParams {
    // Exception is thrown on the line below this
    NSDictionary *pt_data = @{@"pt_phone"       : _phone,
                              @"or_cash"        : (_has_insurance ? @"0" : @"1"),
                              @"pt_email"       : _email,
                              @"pt_country"     : _country,
                              @"pt_state"       : _state,
                              @"pt_address1"    : _address,
                              @"pt_address2"    : _address2,
                              @"pt_city"        : _city,
                              @"pt_uname"       : _name,
                              @"or_regid"       : _device_id,
                              @"pt_deviceid"    : _device_id,
                              @"pt_zip"         : _zip,
                              @"pt_devicetype"  : @"ios"};
    // Server expects pt_data value as string
    NSString *pt_data_string = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:pt_data options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    pt_data_string = [pt_data_string stringByReplacingOccurrencesOfString:@"\n" withString:@" "];

    return @{@"pt_data" : pt_data_string};
}

Apple的崩溃日志

Process:             RxToMe [5640]
Code Type:           ARM-64 (Native)
Parent Process:      launchd [1]
OS Version:          iOS 9.0.2 (13A452)
Report Version:      105

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                 0x182aa0f5c __exceptionPreprocess + 124
1   libobjc.A.dylib               0x197673f80 objc_exception_throw + 56
2   CoreFoundation                 0x18298f8e8 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 324
3   CoreFoundation                 0x18298f780 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 64
4   RxToMe                         0x1000d4bac -[User formatUserParams] (in RxToMe) (User.m:213)
5   RxToMe                         0x1000d3e7c -[User registerAccount] (in RxToMe) (User.m:138)
6   RxToMe                         0x1000d25cc -[ConfirmationViewController completeButtonPressed:] (in RxToMe) (ConfirmationViewController.m:175)
7   UIKit                         0x18802e3c8 -[UIApplication sendAction:to:from:forEvent:] + 100
8   UIKit                         0x1881ad3dc -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 168
9   UIKit                         0x18802e3c8 -[UIApplication sendAction:to:from:forEvent:] + 100
10  UIKit                         0x18802e344 -[UIControl sendAction:to:forEvent:] + 80
11  UIKit                         0x188016c6c -[UIControl _sendActionsForEvents:withEvent:] + 416
12  UIKit                         0x188016db8 -[UIControl _sendActionsForEvents:withEvent:] + 748
13  UIKit                         0x18802dc5c -[UIControl touchesEnded:withEvent:] + 572
14  UIKit                         0x18802d88c -[UIWindow _sendTouchesForEvent:] + 804
15  UIKit                         0x188026ac0 -[UIWindow sendEvent:] + 784
16  UIKit                         0x187ff7a10 -[UIApplication sendEvent:] + 248
17  UIKit                         0x187ff5efc _UIApplicationHandleEventQueue + 5348
18  CoreFoundation                 0x182a585a4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
19  CoreFoundation                 0x182a58038 __CFRunLoopDoSources0 + 540
20  CoreFoundation                 0x182a55d38 __CFRunLoopRun + 724
21  CoreFoundation                 0x182984dc0 CFRunLoopRunSpecific + 384
22  GraphicsServices               0x18d92c088 GSEventRunModal + 180
23  UIKit                         0x18805ef44 UIApplicationMain + 204
24  RxToMe                         0x1000d7c90 0x1000c8000 + 64656
25  libdyld.dylib                 0x197e928b8 start + 4

1 个答案:

答案 0 :(得分:2)

看起来您传入字典的其中一个值是nil,这是不允许的。仔细检查进入字典的所有各种ivars(_phone_email等),并在调用此方法时查看哪些可能为nil。