我一收到通知就试图从iCal中删除该事件。只有在iCal处于后台时,事件才会被删除。如果在关闭iCal后发送相同的通知,则不会删除该事件。正在尝试使用此方法在MyCal宪兵中访问iCal。
+ (void)requestAccess:(void (^)(BOOL granted, NSError *error))callback {
if (eventStore == nil) {
eventStore = [[EKEventStore alloc] init];
}
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:callback];
}正在尝试使用AppDelate.m中的以下方法删除事件
[MyCalendar requestAccess:^(BOOL granted, NSError *error) {
if (granted) {
if ([[self.launchOptions objectForKey:@"type"] isEqualToString:@"remainder"] || [[self.launchOptions objectForKey:@"type"] isEqualToString:@"cancelAppointment"]) {
if ([[self.launchOptions objectForKey:@"type"]
isEqualToString:@"cancelAppointment"]) {
if (![MyCalendar removeEventWithEventIdentifier:
[self.launchOptions objectForKey:@"eventId"]]) {
}
}
}
}
}];M中使用下面的方法从iCal中删除事件
+ (BOOL)removeEventWithEventIdentifier:(NSString *)identifier {
EKEvent *event2 = [eventStore eventWithIdentifier:identifier];
BOOL result = NO;
if (event2 != nil) {
NSError *error = nil;
result = [eventStore removeEvent:event2 span:EKSpanThisEvent error:&error];
}
return result;
}提前感谢!
发布于 2015-06-15 10:32:46
在使用之前,必须初始化事件存储对象。
+ (BOOL)removeEventWithEventIdentifier:(NSString *)identifier {
EKEventStore* eventStore = [[EKEventStore alloc] init];
EKEvent *event2 = [eventStore eventWithIdentifier:identifier];
BOOL result = NO;
if (event2 != nil) {
NSError *error = nil;
result = [eventStore removeEvent:event2 span:EKSpanThisEvent error:&error];
}
return result;
}https://stackoverflow.com/questions/30838868
复制相似问题