EQEvent eventIdentifier returns null

When I try to get the EKEvent ID, all I get is the nil value. Since in iOS5, EKEvent is a subclass of EKCalendarItem, I decided that I could get the UUID of EKCalendarItem, but that also returns zero.

From time to time, I also get this error when trying to access the identifier property or UUID:

CADObjectGetInlineStringProperty failed fetching uniqueID for EKPersistentEvent with error Error Domain=NSMachErrorDomain Code=268435459 "The operation couldn't be completed. (Mach error 268435459 - (ipc/send) invalid destination port)" 

I’ve been stuck with this issue for a long time, but decided it would be a beta version of iOS5. But since we are now in iOS5, it still does not work.

+6
source share
7 answers

When I try to get the EKEvent ID, all I get is nil

Try to save and record your event until you get the identifier:

 [eventStore saveEvent:event span:EKSpanThisEvent commit:YES error:&err]; NSString *strId = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier]; 
+7
source

In my application, I found out that if you request an eventIdentifier, when the eventStore that selected it was issued, it returns nil. But if you ask for an eventIdentifier before it returns id ok. Then you can free the EKEventStore instance and request the id without any problems. It looks like he needs an eventStore to get the identifier, but I don't get any warnings.

+7
source

eventIdentifier is set when an event is added to the EKEventStore. If you try to access this value before adding it, it will return null.

+2
source

Just going through this problem, the eventIdentifier will be null before committing to the database, so you need a commit: YES in the saveEvent function [self.eventStore saveEvent:event span:EKSpanThisEvent commit:YES error:&error];

After that you can receive eventIdentifier.

My mistake was passing NO for commit: parameter.

+2
source

For me, eventIdentifier is null because I did not set endDate . Thus, usually an eventIdentifier can be null if there is any error when creating this event. You can check for the following errors:

 NSError *err = nil; [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err]; NSLog(@"Error : %@",err); 
0
source

The EKEvent event ID is not generated until the event is saved. You can get / save eventIdentifier after you save the event in EKEventStore

  [store saveEvent:event span:EKSpanThisEvent error:&err]; NSString *eventIdentifier = event.eventIdentifier; 
0
source

For Swift 3

I found out that the problem was that I created the repository in a function that retrieves the date.

Creating storage outside the function and using its instance solved the problem.

 class CalendarServices: NSObject { var store = EKEventStore() func fetchEventKitCalendarEvents(date: Date, completion: @escaping (_ events: [EKEvent]?, _ error: Error?)->()) { let calendar = Calendar.current guard self.getEventKitAuthorizationStatus() == .authorized else { completion(nil, CoreServices.setError(message: "AuthorizationStatus != authorized")) return } guard let endDate = calendar.date(byAdding: .day, value: 1, to: date) else { completion(nil, CoreServices.setError(message: "Error creating endDate")) return } CoreServices.background { let predicate = self.store.predicateForEvents(withStart: date, end: endDate, calendars: self.fetchEventKitCalendars()) let events = self.store.events(matching: predicate).sorted() { (e1: EKEvent, e2: EKEvent) -> Bool in return e1.startDate.compare(e2.startDate) == .orderedAscending } CoreServices.async { completion(events, nil) } } } } 
0
source

Source: https://habr.com/ru/post/899302/


All Articles