【问题标题】:Saving iOS Calendar Event is now giving an error保存 iOS 日历事件现在给出错误
【发布时间】:2015-11-09 15:22:52
【问题描述】:
Error pushing dirty properties for EKPersistentLocation to daemon: Error Domain=NSMachErrorDomain Code=4097 "unknown error code"
Connection interrupted!

关于为什么我不能再保存我的活动有什么想法吗?

    NSString *eventIdentifier = ...
    EKEventStore *store = [EKEventStore new];
    EKEvent *event = [store eventWithIdentifier:eventIdentifier];
    if(event == nil) {
        event = [EKEvent eventWithEventStore:store];
    }

    //fill event code here

    //save event
    NSError *error = nil;
    BOOL success = [store saveEvent:event span:EKSpanThisEvent commit:YES error:&error];
    if(error) {
        @throw error;
    }

    if(!success) {
        @throw [Error ERROR_EVENT_SYNC_FAILED_NO_ERROR];
    }

有趣的是,没有生成错误对象,但成功为 NO。错误代码和消息不是特别有用。我不确定脏属性是什么意思,但我不是重复使用旧事件,而是从商店中抓取一个或每次都制作一个新事件。我也不知道连接中断是什么意思。

任何帮助将不胜感激。

【问题讨论】:

    标签: ios runtime-error ekevent ekeventstore


    【解决方案1】:

    我遇到了类似的错误。它是由请求访问 .event 类型的事件并尝试保存提醒引起的。如果您将日历条目保存为事件,则请求访问 .event 如果您请求访问提醒,则请求访问 .reminder 类型。
    以下是请求访问提醒的示例。

        override func viewWillAppear(_ animated: Bool) {
                self.eventStore = EKEventStore()
                self.reminders = [EKReminder]()
                self.eventStore.requestAccess(to: .reminder, completion: requestAccessCompletionHandler)
            }
    
            func requestAccessCompletionHandler (granted: Bool, error: Error?) {
                NSLog("requestAccessCompletionHandler")
                if (granted) {
    
                    let predicate = self.eventStore.predicateForReminders(in: nil)
                    self.eventStore.fetchReminders(matching: predicate, completion: { (reminders: [EKReminder]?) -> Void in
                        self.reminders = reminders
                        DispatchQueue.main.async {
                            self.tableView.reloadData()
                        }
                    })
                } else {
                    print("The app is not permitted to access reminders, make sure to grant permission in the settings and try again")
                }
            }
    

    【讨论】:

      【解决方案2】:

      对于任何想知道的人,“脏属性”是指未分配正确类型的 EKEvent 属性。标题中的“现在给出错误”是因为该特定的代码分支在被调用之前由于更改和正确的代码而没有被调用。

      【讨论】:

        【解决方案3】:

        为了方便其他人搜索与 EventKit 相关的 NSMachErrorDomain Code=4097,我最近在更新跨度为 .futureEvents 的重复事件的 startDateendDate 属性时开始看到此代码,但未提交立即进行更改。

        调用:

        try eventStore.save(event, span: span, commit: false)

        以及稍后关闭编辑屏幕时:

        try eventStore.save(event, span: span, commit: true)

        第二次调用抛出错误,不提交更改,并在控制台中显示此输出:

        Month 13 is out of bounds [EventKit] Failed to get melted object for frozen object related by key detachedItems. Event store is nil [EventKit] Connection interrupted! [CADXPCProxyHelper] Received error from calaccessd connection: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.calaccessd" UserInfo={NSDebugDescription=connection to service named com.apple.calaccessd}. Attempting to call any reply handler. [EventKit] Error committing event store: [Error Domain=NSMachErrorDomain Code=4097 "unknown error code"]

        编辑:我发现真正的问题是我与commit: false 的初始调用使用.futureEvents,但我的函数没有更新所选范围,所以第二次调用是默认为.thisEvent。似乎跨度之间的这种不匹配导致了错误。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-02-04
          • 1970-01-01
          • 2019-05-12
          • 1970-01-01
          • 2017-07-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多