The problem:
- User reports iOS crashes when calling
datePicker.preferredDatePickerStyle = ...in Swift or[self.datePicker setPreferredDatePickerStyle:UIDatePickerStyleInline]in Objective-C - The app is available from iOS 12+ but this code is only called in iOS 14+
- I was not able to reproduce the issue on any device or in simulator
- No other users reported the same problem
Details:
A user of my iOS 12+ reported that the app crashes after the update when using different features. The user send me multiple crash reports and I was able to symbolicate them using Xcode. The reports show, that the crash occurs in two different view controllers but in the same situation: When setting the preferredDatePickerStyle of UIDatePicker.
One view controller uses Objective-C while the other is newer and uses swift:
// Swift
class MyViewControllerA {
@IBOutlet var datePicker: UIDatePicker!
...
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 14.0, *) {
datePicker.preferredDatePickerStyle = .inline // << CRASH
}
...
}
}
// Objective-C
@interface MyViewControllerB : UIViewController
...
@property (strong, nonatomic) IBOutlet UIDatePicker *datePicker;
@end
...
- (void)viewDidLoad {
[super viewDidLoad];
...
if (@available(iOS 14, *)) {
[self.datePicker setPreferredDatePickerStyle:UIDatePickerStyleInline]; // << CRASH
}
}
preferredDatePickerStyle is available since iOS 13.4+, thus calling it with if (@available(iOS 14, *)) should be not problem, should it?
I cannot see anything problematic at these lines. There is no reason why datePicker should be nil in the Swift VC and if it would be nil in the Objective-C version it would be no problem, would it?
There are no reports by other users and I was not able to reproduce the issue in several test. Everything works just as expected.
Crash Reports:
These are the device details from the crash reports:
Hardware Model: iPhone10,6
Process: MyApp [12455]
Path: /private/var/containers/Bundle/Application/UUID/MyApp.app/MyApp
Identifier: com.example.MyApp
Version: 3.0.2.1 (3.0.2)
AppStoreTools: 12D4d
AppVariant: 1:iPhone10,6:13
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: com.example.MyApp [910]
Date/Time: 2021-02-18 15:00:30.0155 +0200
Launch Time: 2021-02-18 15:00:24.0409 +0200
OS Version: iPhone OS 14.4 (18D52)
Release Type: User
Baseband Version: 4.02.01
Report Version: 104
Crash Report in Objective-C VC:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Application Specific Information:
abort() called
Last Exception Backtrace:
0 CoreFoundation 0x18b3999d8 0x18b27f000 + 1157592
1 libobjc.A.dylib 0x19f71fb54 0x19f719000 + 27476
2 CoreFoundation 0x18b2a850c 0x18b27f000 + 169228
3 Foundation 0x18c5a2878 0x18c52b000 + 489592
4 UIKitCore 0x18e1160f0 0x18d0d6000 + 17039600
5 UIKitCore 0x18d7716f4 0x18d0d6000 + 6928116
6 UIKitCore 0x18d8524f4 0x18d0d6000 + 7849204
7 UIKitCore 0x18d84fad0 0x18d0d6000 + 7838416
8 UIKitCore 0x18d850fe4 0x18d0d6000 + 7843812
9 UIKitCore 0x18d851224 0x18d0d6000 + 7844388
10 UIKitCore 0x18d17b938 0x18d0d6000 + 678200
11 UIKitCore 0x18d17bcd8 0x18d0d6000 + 679128
12 UIKitCore 0x18d17d354 0x18d0d6000 + 684884
13 UIKitCore 0x18db77584 0x18d0d6000 + 11146628
14 UIKitCore 0x18db7a1f8 0x18d0d6000 + 11158008
15 MyApp 0x102b51d94 -[DatePickerViewController viewDidLoad] + 712084 (DatePickerViewController.m:88)
16 UIKitCore 0x18d53ee50 0x18d0d6000 + 4623952
17 UIKitCore 0x18d543408 0x18d0d6000 + 4641800
18 UIKitCore 0x18d5437e8 0x18d0d6000 + 4642792
Crash Report in Swift VC
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Application Specific Information:
abort() called
Last Exception Backtrace:
0 CoreFoundation 0x18b3999d8 0x18b27f000 + 1157592
1 libobjc.A.dylib 0x19f71fb54 0x19f719000 + 27476
2 CoreFoundation 0x18b2a850c 0x18b27f000 + 169228
3 Foundation 0x18c5a2878 0x18c52b000 + 489592
4 UIKitCore 0x18e1160f0 0x18d0d6000 + 17039600
5 UIKitCore 0x18d7716f4 0x18d0d6000 + 6928116
6 UIKitCore 0x18d8524f4 0x18d0d6000 + 7849204
7 UIKitCore 0x18d84fad0 0x18d0d6000 + 7838416
8 UIKitCore 0x18d850fe4 0x18d0d6000 + 7843812
9 UIKitCore 0x18d851224 0x18d0d6000 + 7844388
10 UIKitCore 0x18d17b938 0x18d0d6000 + 678200
11 UIKitCore 0x18d17bcd8 0x18d0d6000 + 679128
12 UIKitCore 0x18d17d354 0x18d0d6000 + 684884
13 UIKitCore 0x18db77584 0x18d0d6000 + 11146628
14 UIKitCore 0x18db7a1f8 0x18d0d6000 + 11158008
15 MyApp 0x104345ce8 EditPageViewController.viewDidLoad() + 2284776 (ContractEditPageViewController.swift:107)
16 MyApp 0x104345fdc @objc EditPageViewController.viewDidLoad() + 2285532 (<compiler-generated>:0)
17 UIKitCore 0x18d53ee50 0x18d0d6000 + 4623952
18 UIKitCore 0x18d543408 0x18d0d6000 + 4641800
Any idea how to find out what is going wrong?