小胖说事-------iOS利用代码添加事件到系统日历中
来源:互联网 发布:商场消费数据 编辑:程序博客网 时间:2024/04/25 18:00
#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
0 0
- 小胖说事-------iOS利用代码添加事件到系统日历中
- iOS利用代码添加事件到系统日历中
- iOS利用代码添加事件到系统日历中
- iOS 添加事件到系统日历中
- ios中将事件添加到系统日历
- iOS添加事件到系统日历
- ios中将事件添加到系统日历
- iOS开发 添加事件到系统日历
- 【iOS学习笔记】中将事件添加到系统日历
- 将事件添加到系统日历中,并且添加到提醒事项中
- iOS学习笔记54-ios中将事件添加到系统日历
- Android 向系统日历中添加事件
- IOS添加日历事件
- iOS 添加日历事件
- iOS开发将App发布的事件直接添加到系统日历提醒事项的封装
- Android添加事件到日历
- ios 添加日历提醒事件
- iOS日历中给一个事件添加多个提醒
- Meta http-equiv属性详解
- Recyclerview
- hadoop 参数配置
- 食物链
- Java中静态变量的适用场景
- 小胖说事-------iOS利用代码添加事件到系统日历中
- Sqlite数据库添加,删除前n条记录
- SuperMap iObject常见问题解答集锦(五)
- Linux 删除文件夹和文件的命令
- java.lang.IllegalArgumentException: Illegal character in query at index
- 二分 + 快排
- Android 6.0权限动态申请
- RadioGroup与RadioButton详解
- JavaScript和iOS交互遇到的坑