EKEventStore* eventStore = [[EKEventStore alloc] init];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
NSLog(@"添加提醒失败");
return ;
}
if (!granted) {
NSLog(@"没有权限");
return;
}
EKEvent* event = [EKEvent eventWithEventStore:eventStore];
event.title = @"这个是event的title";
event.location = @"这个是event的location";
event.startDate = [NSDate date];
event.endDate = [NSDate date];
event.allDay = YES;
[event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -60.0f * 24]];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
[eventStore saveEvent:event span:EKSpanThisEvent error:nil];
});
}];
}
iOS如何写入日历 提醒?
最新推荐文章于 2021-12-05 09:00:00 发布
本文详细介绍了如何使用EKEventStore类创建、配置并保存事件提醒,包括请求权限、设置事件属性、添加提醒等功能。通过实例代码演示了整个流程。
1530

被折叠的 条评论
为什么被折叠?



