简体   繁体   English

使用EventKit创建提醒时出错

[英]Error creating reminder using EventKit

I have an app that uses EventKit. 我有一个使用EventKit的应用程序。 I ask for permission for reminders and then I have code that creates a reminder. 我要求获得提醒的许可,然后我拥有创建提醒的代码。 I sometimes get this error message in my logs when running the app in the simulator: 在模拟器中运行应用程序时,有时会在日志中收到此错误消息:

Error getting changed object IDs since timestamp 450512391.766620 from daemon: Error Domain=EKCADErrorDomain Code=1013 "The operation couldn't be completed. (EKCADErrorDomain error 1013.)" Error getting default calendar for new reminders: Error Domain=EKCADErrorDomain Code=1013 "The operation couldn't be completed. (EKCADErrorDomain error 1013.)"

The first error comes from the authorization step and second comes from these lines: 第一个错误来自授权步骤,第二个错误来自以下行:

EKReminder *reminder = [EKReminder reminderWithEventStore:eventStore]; reminder.calendar = eventStore.defaultCalendarForNewReminders;

This happens after requestAccessToEntityType:completion: returns granted permission for reminders, so there is definitely permission. 发生这种情况是在requestAccessToEntityType:completion:返回授予提醒的权限之后,因此肯定有权限。

The weird thing is, once the issue happens if I just restart the app everything is fine. 奇怪的是,一旦发生问题,如果我重新启动应用程序,一切都会好起来。 If I reset the simulator and rerun the app this only sometimes will happen again. 如果我重置模拟器并重新运行应用程序,则仅有时会再次发生。

This seems to only happen with the following workflow: 这似乎仅在以下工作流程中发生:

  • Reset All Contact and Settings Menu Option. 重置所有联系人和设置菜单选项。
  • Quit simulator right away when it comes back up. 回来后立即退出模拟器。
  • Run your app which immediately asks for Calendar info on the just-reset, never-opened-before simulator. 运行您的应用程序,该应用程序立即在刚刚重置且从未打开过的模拟器上询问日历信息。

I suspect the reason is because when you reset the entire simulator, it needs a few seconds to initialize all the demo data such as the contacts and calendar events when it "boots" for the first time. 我怀疑原因是因为当您重置整个模拟器时,首次启动时它需要几秒钟的时间来初始化所有演示数据,例如联系人和日历事件。

If you wait 10+ seconds after reset, THEN run your app, you do not get this warning. 如果您在重置后等待10秒钟以上,然后运行您的应用,则不会收到此警告。

Another workaround is to use the "Reset Privacy Settings" in iOS Simulator Settings App (General > Reset) during testing of calendar permission testing. 另一个解决方法是在日历权限测试的测试过程中使用iOS Simulator Settings App中的“重置隐私设置”(“常规”>“重置”)。

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

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