1
我無法保存我的提醒/事件。但我已被授予使用提醒的權限(我檢查了設置)。我已經打印出錯誤,它說That event does not belong to that event store.
這是我的代碼;EKEventStore - 該事件不屬於該事件存儲區
- (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]);
}
哪裏有問題的建議?
對不起,'_eventStore'從哪裏來?它與'self.eventStore'不同嗎? – logc