ios中将事件添加到系统日历
- (void)saveEvent:(id)sender { //事件市场
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 * ]];
[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(@"保存成功"); }
});
}];
}
else
{
// this code runs in iOS 4 or iOS 5
// ***** do the important stuff here ***** //4.0和5.0通过下述方式添加 //保存日历
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 * ]];
[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(@"保存成功"); }
}
ios中将事件添加到系统日历的更多相关文章
- ios中将事件同步到系统日历
//获取日历事件 EKEventStore* eventStore = [[EKEventStorealloc] init]; NSDate* ssdate = [NSDatedateWithTime ...
- Android 向系统日历中添加事件
查了一天半,总算有点大概了.以下是自己的理解,有错误的地方望指正. android系统有日历功能,应用程序可以根据一些接口开发自己的功能,即使是日历app也是根据这些接口开发的,所以我们可以利用程序向 ...
- Android向系统日历中添加日程事件
转自Android向系统日历中添加日程事件 总结 在项目开发中,我们有预约提醒.定时提醒需求时,可以使用系统日历来辅助提醒: 通过向系统日历中写入事件.设置提醒方式(闹钟),实现到时间自动提醒的功能: ...
- Android向系统日历添加日程提醒事件
在项目开发过程中,有时会有预约提醒.定时提醒等需求,这时我们可以使用系统日历来辅助提醒.通过向系统日历中写入事件.设置提醒方式(闹钟),实现到达某个特定的时间自动提醒的功能.这样做的好处是由于提醒功能 ...
- 史上最详细的iOS之事件的传递和响应机制
前言: 按照时间顺序,事件的生命周期是这样的: 事件的产生和传递(事件如何从父控件传递到子控件并寻找到最合适的view.寻找最合适的view的底层实现.拦截事件的处理)->找到最合适的view后 ...
- IOS触摸事件和手势识别
IOS触摸事件和手势识别 目录 概述 触摸事件 手势识别 概述 为了实现一些新的需求,我们常常需要给IOS添加触摸事件和手势识别 触摸事件 触摸事件的四种方法 -(void)touchesBegan: ...
- Xamarin iOS教程之添加和定制视图
Xamarin iOS教程之添加和定制视图 Xamarin iOS用户界面——视图 在iPhone或者iPad中,用户看到的摸到的都是视图.视图是用户界面的重要组成元素.例如,想要让用户实现文本输入时 ...
- iOS之事件的传递和响应机制
前言: 按照时间顺序,事件的生命周期是这样的: 事件的产生和传递(事件如何从父控件传递到子控件并寻找到最合适的view.寻找最合适的view的底层实现.拦截事件的处理)->找到最合适的view后 ...
- IOS 为UILabel添加长按复制功能
IOS 为UILabel添加长按复制功能 在iOS中下面三个控件,自身就有复制-粘贴的功能: 1.UITextView 2.UITextField 3.UIWebView UIKit framewor ...
随机推荐
- [算法]——全排列(Permutation)以及next_permutation
排列(Arrangement),简单讲是从N个不同元素中取出M个,按照一定顺序排成一列,通常用A(M,N)表示.当M=N时,称为全排列(Permutation).从数学角度讲,全排列的个数A(N,N) ...
- HTTP02--Http请求头及缓存知识
一.常用工具 Linux下:curl命令,I参数可以查看http head信息. Firefox:Firebug.HttpFox 二.常见Http Head信息 三.浏览器缓存机制 使用ctrl+F5 ...
- TSQL的连乘
某个需求需要对某一列的值做乘法,网上搜了把确实还真没有直接的聚合函数用于将某一列的值乘起来. 找到了替代的算法: http://jerryyang-wxy.blogspot.com/2012/04/t ...
- [转]js动态获取图片长宽尺寸
http://blog.phpdr.net/js-get-image-size.html lightbox类效果为了让图片居中显示而使用预加载,需要等待完全加载完毕才能显示,体验不佳(如filick相 ...
- 写给自己看的Linux运维基础(一) - 系统基础
查看内核版本信息 uname -a 查看发行版本 cat /etc/issue 查看硬件配置 CPU: cat /proc/cpuinfo more /proc/cpuinfo | grep ...
- [ACM_搜索] POJ 1096 Space Station Shielding (搜索 + 洪泛算法Flood_Fill)
Description Roger Wilco is in charge of the design of a low orbiting space station for the planet Ma ...
- 谷歌(Chrome)浏览器调试JavaScript小技巧
谷歌浏览器不仅仅可以用来上网,对于开发人员来说,它更像是一款强大的开发辅助工具. 工欲善其事必先利其器,接下来笔者给大家分享一些Chrome的使用方法. 假如读者了解如何在Chrome中添加JavaS ...
- 深入浅出OOP(四): 多态和继承(抽象类)
在本文中,我们讨论OOP中的热点之一:抽象类.抽象类在各个编程语言中概念是一致的,但是C#稍微有些不一样.本文中我们会通过代码来实现抽象类,并一一进行解析. Abstract Classes 在微软的 ...
- 使用Jekyll官方的ReadMore摘要功能
今天才发现,Jekyll官方就支持ReadMore摘要功能,记录一下. 我之前的方法,在index.html中 {{ post.content ||split:'<!-- more --> ...
- JQuery文本框水印插件的简单实现
采用JQuery实现文本框的水印效果非常容易,效果如下: 代码片段,定义要应用水印效果的文本框的样式: .watermark { color: #cccccc; } 将JavaScript代码封装成J ...