gpt4 book ai didi

ios - 当 iCal 不在后台时,从 iCal 中删除事件不起作用

转载 作者:搜寻专家 更新时间:2023-10-30 20:15:47 24 4
gpt4 key购买 nike

我正在尝试在收到通知后立即从 iCal 中删除事件。仅当 iCal 在后台时,事件才会被删除。如果在关闭 iCal 后发送相同的通知,则事件不会被删除。我正在尝试在 MyCalendar.m 中使用此方法访问 iCal

+ (void)requestAccess:(void (^)(BOOL granted, NSError *error))callback {
if (eventStore == nil) {
eventStore = [[EKEventStore alloc] init];
}
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:callback];
}

我正在尝试使用 Appdelegate.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"]]) {
}
}
}
}
}];

正在使用 MyCalendar.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;
}

提前致谢!

最佳答案

您必须在使用前初始化事件存储对象。

    + (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;
}

关于ios - 当 iCal 不在后台时,从 iCal 中删除事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30838868/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com