小胖说事-------iOS利用代码添加事件到系统日历中
2016-08-17 11:44
381 查看
#import <EventKit/EventKit.h> //事件市场 EKEventStore *eventStore = [[EKEventStore alloc] init]; //6.0及以上通过下面方式写入事件 if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) { // the selector is available, so we must be on iOS 6 or newer [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ if (error) { //错误细心 // display error message here } else if (!granted) { //被用户拒绝,不允许访问日历 // display access denied error message here } else { // access granted // ***** do the important stuff here ***** //事件保存到日历 //创建事件 EKEvent *event = [EKEvent eventWithEventStore:eventStore]; event.title = @"哈哈哈,我是日历事件啊"; event.location = @"我在杭州西湖区留和路"; NSDateFormatter *tempFormatter = [[NSDateFormatter alloc]init]; [tempFormatter setDateFormat:@"dd.MM.yyyy HH:mm"]; event.startDate = [[NSDate alloc]init ]; event.endDate = [[NSDate alloc]init ]; event.allDay = YES; //添加提醒 [event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -60.0f * 24]]; [event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -15.0f]]; [event setCalendar:[eventStore defaultCalendarForNewEvents]]; NSError *err; [eventStore saveEvent:event span:EKSpanThisEvent error:&err]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Event Created" message:@"Yay!?" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil]; [alert show]; NSLog(@"保存成功"); } }); }]; }
原文地址:http://www.cnblogs.com/xiaobaichangan/p/5160025.html
相关文章推荐
- iOS利用代码添加事件到系统日历中
- iOS利用代码添加事件到系统日历中
- 小胖说事----------调用系统日历,显示某一个时间并且弹出系统日历的添加事件页面
- 【iOS学习笔记】中将事件添加到系统日历
- iOS 添加事件到系统日历中
- iOS添加事件到系统日历
- ios中将事件添加到系统日历
- 设置代码ios 6添加日历事件No calendar has been set.错误
- iOS开发将App发布的事件直接添加到系统日历提醒事项的封装
- iOS学习笔记54-ios中将事件添加到系统日历
- ios中将事件添加到系统日历
- iOS开发 添加事件到系统日历
- ios中将事件添加到系统日历
- ios中将事件添加到系统日历
- 小胖说事12--------iOS App集成Apple Pay教程(附示例代码)
- jQuery支持添加事件的日历特效代码分享(3种样式)
- 向系统日历添加一条事件(时间指定)
- iOS日历中给一个事件添加多个提醒
- IOS开发-14.利用代码添加autolayout约束
- iOS日历中给一个事件添加多个提醒