简体   繁体   English

iOS 11中的EventKit导致问题

[英]EventKit in iOS 11 Causing Problems

Since I upgraded my app to Xcode 9 and iOS 11, I've been experiencing some inconsistencies with EventKit. 自从我将我的应用程序升级到Xcode 9和iOS 11后,我遇到了一些与EventKit不一致的问题。

  • For example, when creating a new event, the event.eventIdentifier is returning nil, when the property is declared as String!. 例如,在创建新事件时,当属性声明为String!时,event.eventIdentifier返回nil。 Before iOS11, it returned an empty string 在iOS11之前,它返回一个空字符串
  • 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!. 另一个问题是我的一个用户在该属性也定义为String!时也获得了一个nil标题。
  • I'm getting another report that my app os crashing when using the standard EventKitUI editor when editing a particular task. 我在编辑特定任务时使用标准EventKitUI编辑器时,我的另一个报告是我的应用程序崩溃了。

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 更新 :Apple已将我的错误报告标记为重复:34134523

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)" [EventKit]获取新事件的默认日历时出错:Error Domain = EKCADErrorDomain Code = 1019“(null)”

Well, if it is String! 好吧,如果是String! (an implicitly unwrapped Optional ) it can return nil. (一个隐式解包的可选 )它可以返回nil。 (just to be clear: if nil wouldn't be a possible return value, it would be just String , which provides exactly that guarantee.) (只是要明确:如果nil不是一个可能的返回值,它将只是String ,它提供了完全保证。)

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?]). 如果一个API返回一个可选项,你需要检查nil(虽然它们应该使它成为一个常规的可选[也许他们在Swift 4编译时会这样做?])。 It could be something as simple as event.title ?? 'no title' 它可能像event.title ?? 'no title'一样简单event.title ?? 'no title' event.title ?? 'no title' . 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. 第一个是API中的修复,为eventIdentifier返回一个空字符串是eventIdentifier错误的。 It has to return nil (meaning no identifier assigned). 它必须返回nil(意味着没有分配标识符)。

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). 标题不是iCalendar(SUMMARY属性)中的必填字段,因此API现在正确反映了缺少的标题(与空标题相对)。

Assuming they didn't change the API (which I think is not the case for 3.2), all this seems fine. 假设他们没有改变API(我认为不是3.2的情况),所有这一切似乎都很好。 Your code didn't properly check for nil values. 您的代码未正确检查nil值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM