Removing events from iPhone calendar with EKEventStore

后端 未结 2 786
野性不改
野性不改 2020-12-29 00:48

I\'m trying to remove events that i have created from the iPhone calendar.

I tried this, but it always returns NO:

  [eventStore removeEvent:event sp         


        
2条回答
  •  生来不讨喜
    2020-12-29 01:11

    Just an FYI for the answer above. It is found on the web on with this link: http://tech.vniup.com/index.php/iphone/objective-c/how-to-delete-event-from-iphone-calendar-programmatically.html

    My only suggestion is that if you are building an array of objects each object ideally would be the event. Then do a reverse array operation because the latest event will always be at the bottom.

    NSMutableArray *reverseArray = [NSMutableArray arrayWithCapacity:[eventsList count]];
    
    for (id element in [eventsList reverseObjectEnumerator]) {
        [reverseArray addObject:element];
    }
    eventsList = reverseArray;
    

    And also in the display of the events be nice to your users and display the start date of the event.

    Anyway, after you have an array objects that are EKEvents you can do this which is MUCH easier.

    EKEvent *eventToRemove = [myEventStore eventWithIdentifier:thisEvent.eventIdentifier ];
            if ([eventToRemove.eventIdentifier length] > 0) {
                NSError* error = nil;
                [myEventStore removeEvent:eventToRemove span:EKSpanThisEvent error:&error];
                }
    

    Then you can remove that same event from you array of events for the table display....easy!

提交回复
热议问题