gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:37:15 24 4
gpt4 key购买 nike

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

最佳答案

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

关于ios - 为什么这个方法会抛出异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33419558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com