EKEventEditViewController crashes if event has startDate filled

Originator:nicolai
Number:rdar://45383700 Date Originated:October 18 2018
Status:open Resolved:
Product:iOS + SDK Product Version:12
Classification:bug Reproducible:always
 
When using EKEventEditViewController to add or edit an event, the application crashes if the EKEvent used as input to EKEventEditViewController has the startDate field set.

This is true both for creating new events and for editing existing events.

This will only crash on device. On simulator the EventUI is shown as expected but this is output in the console:
2018-10-18 23:01:25.363585+0200 EventKitUICrash[289:5623904] *** -[__NSCFCalendar components:fromDate:]: date cannot be nil
(and a stacktrace similar to when run on device from Xcode

Attached Xcode project that reproduces.

Steps to Reproduce:
1. Create an empty single view iOS project
2. To Info.plist add <key>NSCalendarsUsageDescription</key><string>crash</string>
3. Change ViewController.swift to have this contents:
class ViewController: UIViewController {
    let store = EKEventStore()

    override func viewDidLoad() {
        super.viewDidLoad()

        store.requestAccess(to: .event) { _, _ in
            DispatchQueue.main.async {
                self.showEventEdit()
            }
        }
    }

    func showEventEdit() {
        let event = EKEvent(eventStore: store)
        event.startDate = Date()
        let viewController = EKEventEditViewController()
        viewController.event = event
        viewController.eventStore = store

        present(viewController, animated: true)
    }
}

Expected Results:
EKEventEditViewController to show

Actual Results:
App crashes

Version/Build:
Xcode Version 10.0 (10A255)
iOS 12.0.1

Comments

Apparently this is more complicated than initially thought. Before I could reproduce in our app and in the attached almost-empty project 100 % of the time on my iPhone Xs. I just reproduced the bug on the iPhone Xs multiple time. Then I tried to reproduce on an iPad Pro (also iOS 12.0.1) and could not reproduce. The iPad is using same iCloud account. After I created an event on the iPad with success, I switched to the iPhone Xs again and watched the new event appear. After this event appeared on the iPhone Xs I could create and edit events without crashes both in our app and in the attached project. We have a lot of users that experience this crash so it is very real, but apparently not so easy to isolate the exact circumstances.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!