gpt4 book ai didi

ios - EKEventStore - 该事件不属于该事件存储

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:48 25 4
gpt4 key购买 nike

我根本无法保存我的提醒/事件。但是,我已被授予使用提醒的权限(我检查了设置)。我已经打印出错误,它说 That event does not belong to that event store. 这是我的代码;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

self.eventStore =[[EKEventStore alloc] init];
self.eventStoreAccessGranted = NO;
[self.eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
self.eventStoreAccessGranted = granted;
if (!granted) {
NSLog(@"User has not granted permission");
}
}];

}



- (IBAction)setAReminder:(id)sender {

if (!self.eventStoreAccessGranted) {
NSLog(@"Reminder is no");
return;
}
NSLog(@"Reminder is YES");
EKReminder * newReminder = [[EKReminder alloc] init];
newReminder.title = @"Pick up the kids";
newReminder.calendar = [self.eventStore defaultCalendarForNewReminders];


NSDate *now = [NSDate date];
NSDate *alarmDate = [now dateByAddingTimeInterval:120];
EKAlarm * ourAlarm = [EKAlarm alarmWithAbsoluteDate:alarmDate];

[newReminder addAlarm:ourAlarm];
NSError *error = nil;

[self.eventStore saveReminder:newReminder commit:YES error:&error];
NSLog(@"Event %@",[error localizedDescription]);
}

对问题所在有什么建议吗?

最佳答案

我将我的代码更改为此并且它可以正常工作。

 -(IBAction)setAReminder:(id)sender {

if (self.eventStore == nil)
{
self.eventStore = [[EKEventStore alloc]init];

[self.eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {

if (!granted)
NSLog(@"Access to store not granted");
}];
}

if (self.eventStore != nil)
[self createReminder];

}

-(void)createReminder
{
EKReminder *reminder = [EKReminder
reminderWithEventStore:self.eventStore];

reminder.title = @"Test";

reminder.calendar = [_eventStore defaultCalendarForNewReminders];

NSDate *date = [NSDate date];

EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:[date dateByAddingTimeInterval:120]];

[reminder addAlarm:alarm];

NSError *error = nil;

[_eventStore saveReminder:reminder commit:YES error:&error];

if (error)
NSLog(@"error = %@", error);

}

关于ios - EKEventStore - 该事件不属于该事件存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24656252/

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