EventKit in iOS 11 Causing Problems

Viewed 473

Since I upgraded my app to Xcode 9 and iOS 11, I've been experiencing some inconsistencies with EventKit.

  • For example, when creating a new event, the event.eventIdentifier is returning nil, when the property is declared as String!. Before iOS11, it returned an empty string
  • Another issue is that one of my users is getting also a nil title on an event when the property is also defined as String!.
  • I'm getting another report that my app os crashing when using the standard EventKitUI editor when editing a particular task.

I'm asking if anyone else is experiencing similar issues. I've already filed a bug report a while ago when it was still in beta.

Update: Apple has flagged my bug report as a duplicate of: 34134523

2 Answers

I'm experiencing something similar. It seems to be because it's not able to retrieve the default calendar. I'm seeing this in my unit tests. I haven't yet been able to figure out why the default calendar is failing.

[EventKit] Error getting default calendar for new events: Error Domain=EKCADErrorDomain Code=1019 "(null)"

Well, if it is String! (an implicitly unwrapped Optional) it can return nil. (just to be clear: if nil wouldn't be a possible return value, it would be just String, which provides exactly that guarantee.)

This is likely why you are now crashing on the 3rd point. If an API returns an optional, you need to check for nil (though they should make it a regular Optional [maybe they did when compiling in Swift 4?]). It could be something as simple as event.title ?? 'no title'.

The first two changes also seem reasonable to me.

The first is a fix in the API, returning an empty string for eventIdentifier is plain wrong. It has to return nil (meaning no identifier assigned).

The second also makes sense. The title is not a required field in iCalendar (SUMMARY property), so the API now properly reflects a missing title (vs an empty title).

Assuming they didn't change the API (which I think is not the case for 3.2), all this seems fine. Your code didn't properly check for nil values.

Related