简体   繁体   English

保存iOS日历事件现在出现错误

[英]Saving iOS Calendar Event is now giving an error

Error pushing dirty properties for EKPersistentLocation to daemon: Error Domain=NSMachErrorDomain Code=4097 "unknown error code"
Connection interrupted!

Any ideas as to why I cannot save my events anymore? 关于为什么我不能再保存事件的任何想法?

    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];
    }

Interestingly, no error object is generated but success is NO. 有趣的是,没有错误对象生成,但成功为否。 The error code and message are not particularly helpful. 错误代码和消息不是特别有用。 I am not sure what it means by dirty properties but I am not reusing an old event but grabbing one from the store or making a new one every time. 我不知道肮脏的财产意味着什么,但我不是在重用旧事件,而是每次从商店中抢购一个或制作一个新事件。 I also do not know what Connection Interrupted means. 我也不知道“连接中断”是什么意思。

Any help would be appreciated. 任何帮助,将不胜感激。

I had a similar error. 我有一个类似的错误。 It was caused by requesting access to events of type .event and trying to save a reminder. 这是由于请求访问.event类型的事件并尝试保存提醒引起的。 If you are saving calendar entries as events then request access to .event if you are requesting access to reminders request access of type .reminder. 如果要将日历条目另存为事件,那么如果您请求访问提醒,则请求访问.event,请求访问类型为.reminder。
Below is an example of requesting access to reminders. 以下是请求访问提醒的示例。

    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")
            }
        }

For anyone wondering, the "dirty properties" refer to the EKEvent properties not being assigned the correct type. 对于任何想知道的人,“脏属性”是指未分配正确类型的EKEvent属性。 The "now gives an error" in the title was because that particular branch of code was not getting called due to a change and proper code before it was getting called. 标题中的“现在给出了错误”是因为在调用之前,由于更改和正确的代码,未调用该特定代码分支。

For the benefit of other people searching NSMachErrorDomain Code=4097 in relation to EventKit, I recently started seeing this code when updating the startDate and endDate properties of a repeating event with a span of .futureEvents , but not committing the changes right away. 对于其他人搜索的好处NSMachErrorDomain Code=4097相对于EventKit,我最近开始在更新的时候看到这个代码startDateendDate与跨度重复事件的性质.futureEvents ,但没有提交修改的时候了。

Calling: 致电:

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

and later when dismissing the edit screen: 及以后关闭编辑屏幕时:

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

The second call throws an error, does not commit the changes, and shows this output in the console: 第二个调用将引发错误,不提交更改,并在控制台中显示以下输出:

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"]

Edit: I found out that the real problem was that my initial call with commit: false was using .futureEvents , but my function wasn't updating the selected span, so the second call was defaulting to .thisEvent . 编辑:我发现真正的问题是我最初使用commit: false进行的调用使用的是.futureEvents ,但是我的函数没有更新所选范围,因此第二次调用默认使用.thisEvent It seems that this mismatch between the spans was causing the error. 跨度之间的这种不匹配似乎是导致该错误的原因。

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

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