【发布时间】:2020-01-06 04:28:22
【问题描述】:
我有一个包含日期和时间的字符串。尝试将字符串转换为 NSDate 时,它得到 nil 并且 App 崩溃。它适用于其他 iOS 版本 13、13.1 和 13.2。它只在 iOS 13.3 中崩溃。
代码片段:
NSString *startDateString = @"01-04-2020 8:00pm";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"MM-dd-yyyy h:mma";
NSDate *startDate = [dateFormatter dateFromString:startDateString];
在上述代码中,当我在 iOS 13.3 中调试 startDate 时为零,但它在较低的 iOS 版本中运行良好。
崩溃报告:
2020-01-06 10:04:28.312021+0530 LivingTree[1295:196522] *** Assertion failure in -[_UIDatePickerView _setDate:animated:forced:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3901.4.2/_UIDatePickerView.m:306
2020-01-06 10:04:28.313254+0530 LivingTree[1295:196522] CRASH: Invalid parameter not satisfying: date
2020-01-06 10:04:28.327693+0530 LivingTree[1295:196522] Stack Trace: (
0 CoreFoundation 0x0000000198bec980 93BD750D-2ECE-3E38-8405-9E46EFE482C6 + 1255808
1 libobjc.A.dylib 0x0000000198905028 objc_exception_throw + 60
2 CoreFoundation 0x0000000198ae94fc 93BD750D-2ECE-3E38-8405-9E46EFE482C6 + 193788
3 Foundation 0x0000000198f2a700 80C31587-F538-3437-966F-300F6632EB95 + 571136
4 UIKitCore 0x000000019cc5e634 AA897CA9-8D15-3DD7-BB4F-8D90F9A28571 + 10253876
5 UIKitCore 0x000000019cc5e310 AA897CA9-8D15-3DD7-BB4F-8D90F9A28571 + 10253072
6 UIKitCore 0x000000019cc4dd3c AA897CA9-8D15-3DD7-BB4F-8D90F9A28571 + 10186044
7 LivingTree 0x000000010018e930 -[CreateEventViewController setEditEventData] + 13568
8 LivingTree 0x000000010018b41c __40-[CreateEventViewController viewDidLoad]_block_invoke + 3344
9 libdispatch.dylib 0x0000000101ae1e1c _dispatch_call_block_and_release + 32
10 libdispatch.dylib 0x0000000101ae327c _dispatch_client_callout + 20
11 libdispatch.dylib 0x0000000101af132c _dispatch_main_queue_callback_4CF + 1376
12 CoreFoundation 0x0000000198b67cc8 93BD750D-2ECE-3E38-8405-9E46EFE482C6 + 711880
13 CoreFoundation 0x0000000198b62a24 93BD750D-2ECE-3E38-8405-9E46EFE482C6 + 690724
14 CoreFoundation 0x0000000198b61f40 CFRunLoopRunSpecific + 480
15 GraphicsServices 0x00000001a2ddf534 GSEventRunModal + 108
16 UIKitCore 0x000000019ccdaa60 UIApplicationMain + 1940
17 LivingTree 0x00000001001143f8 main + 124
18 libdyld.dylib 0x00000001989e0e18 9059087B-727B-3B45-B672-09E5B03E6020 + 3608
)
2020-01-06 10:04:28.328420+0530 LivingTree[1295:196522] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: date'
*** First throw call stack:
(0x198bec96c 0x198905028 0x198ae94fc 0x198f2a700 0x19cc5e634 0x19cc5e310 0x19cc4dd3c 0x10018e930 0x10018b41c 0x101ae1e1c 0x101ae327c 0x101af132c 0x198b67cc8 0x198b62a24 0x198b61f40 0x1a2ddf534 0x19ccdaa60 0x1001143f8 0x1989e0e18)
libc++abi.dylib: terminating with uncaught exception of type NSException
【问题讨论】:
-
你能显示崩溃报告吗
-
@Anbu.Karthik 我一定会的
-
@Anbu.Karthik 我已经更新了崩溃报告,请查看
-
愚蠢的问题,但我有我的理由。你使用的是什么版本的 Xcode? (在使用 Xcode 11.3 build 11C29 更新 something 之前,我在物理设备上的 iOS 13.3 中遇到了崩溃。)更有可能?您能否将范围缩小到特定的代码行并找出
UIDatePickerView _setDate中的实际值? -
我运行了你的代码。我没有崩溃。此外,您显示的崩溃似乎与 UIDatePickerView 有关,您没有告诉我们任何信息 - 与您的代码无关。
标签: ios objective-c nsdateformatter