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如何写入日历 提醒?
最新推荐文章于 2023-10-06 10:22:30 发布