我根本无法保存提醒/事件。但是,我已被授予使用提醒的权限(我检查了设置)。我已经打印出错误,并显示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)setAReminderid)sender {
if (!self.eventStoreAccessGranted) {
NSLog(@"Reminder is no");
return;
}
NSLog(@"Reminder is YES");
EKReminder * newReminder = [[EKReminder alloc] init];
newReminder.title = @"ick up the kids";
newReminder.calendar = [self.eventStore defaultCalendarForNewReminders];
NSDate *now = [NSDate date];
NSDate *alarmDate = [now dateByAddingTimeInterval:120];
EKAlarm * ourAlarm = [EKAlarm alarmWithAbsoluteDate:alarmDate];
[newReminder addAlarmurAlarm];
NSError *error = nil;
[self.eventStore saveReminder:newReminder commit:YES error:&error];
NSLog(@"Event %@",[error localizedDescription]);
}
有什么建议可能是问题所在吗?
Best Answer-推荐答案 strong>
我将代码更改为此,并且可以正常工作。
-(IBAction)setAReminderid)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/
|