Swift - 使用EventKit获取系统日历事件,添加事件
通过EventKit可以对iOS日历事件进行读取,添加等操作。但网上找到的都是使用Objective-C来编写的。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import UIKitimport EventKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. var eventStore:EKEventStore = EKEventStore() // 'EKEntityTypeReminder' or 'EKEntityTypeEvent' eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: { granted, error in if (granted) && (error == nil) { println("granted \(granted)") println("error \(error)") // 新建一个事件 var event:EKEvent = EKEvent(eventStore: eventStore) event.title = "新增一个测试事件" event.startDate = NSDate() event.endDate = NSDate() event.notes = "这个是备注" event.calendar = eventStore.defaultCalendarForNewEvents eventStore.saveEvent(event, span: EKSpanThisEvent, error: nil) println("Saved Event") // 获取所有的事件(前后90天) var startDate=NSDate().dateByAddingTimeInterval(-3600*24*90) var endDate=NSDate().dateByAddingTimeInterval(3600*24*90) var predicate2 = eventStore.predicateForEventsWithStartDate(startDate, endDate: endDate, calendars: nil) println("查询范围 开始:\(startDate) 结束:\(endDate)") var eV = eventStore.eventsMatchingPredicate(predicate2) as [EKEvent]! if eV != nil { for i in eV { println("标题 \(i.title)" ) println("开始时间: \(i.startDate)" ) println("结束时间: \(i.endDate)" ) } } } }) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }} |
Swift - 使用EventKit获取系统日历事件,添加事件的更多相关文章
- Android 向系统日历中添加事件
查了一天半,总算有点大概了.以下是自己的理解,有错误的地方望指正. android系统有日历功能,应用程序可以根据一些接口开发自己的功能,即使是日历app也是根据这些接口开发的,所以我们可以利用程序向 ...
- Android向系统日历中添加日程事件
转自Android向系统日历中添加日程事件 总结 在项目开发中,我们有预约提醒.定时提醒需求时,可以使用系统日历来辅助提醒: 通过向系统日历中写入事件.设置提醒方式(闹钟),实现到时间自动提醒的功能: ...
- AJAX获取数据,需要添加事件
如果是通过异步请求从后端获取的数据来渲染页面,要添加事件,必须要在页面已有的元素上,添加时间代理.因为页面渲染需要时间,如果直接绑定在响应时间元素上面,很有可能触发不了事件.
- js兼容方法:事件添加|事件绑定|事件监听 addEvent
function addEvent(obj,sEvent,fn){ if(obj.attachEvent){ obj.attachEvent("on"+sEvent,fn); }e ...
- Android向系统日历添加日程提醒事件
在项目开发过程中,有时会有预约提醒.定时提醒等需求,这时我们可以使用系统日历来辅助提醒.通过向系统日历中写入事件.设置提醒方式(闹钟),实现到达某个特定的时间自动提醒的功能.这样做的好处是由于提醒功能 ...
- Swift动态添加UIImageView并添加事件
Swift动态添加UIImageView并添加事件: 1. 创建UIImageView实例,并进行初始化 2. 设置UIImageView的用户交互属性userInteractionEnabled为T ...
- 获取所有树叶子节点 注册添加事件 if ($(node).tree('isLeaf', node.target)) 是否叶子节点
//获取所有树叶子节点 注册添加事件 if ($(node).tree('isLeaf', node.target)) 是否叶子节点 $(function () { $('.easyui-tree') ...
- DOM2级事件对象、添加事件、阻止默认事件、阻止冒泡事件、获取事件对象目标的兼容处理
事件对象——兼容处理 /* * 功能: 事件对象兼容 * 参数: 表示常规浏览器的事件对象e */ function getEvent(e) { // 如果存在e存在,直接返回,否则返回window. ...
- MySQL的数据类型,MySQL增删改--添加主外键、添加属性、删除主外键、改表名、获取系统当前时间等
ls /etc/rc.d/init.d/mysql56service mysql56 start ps aux |grep "mysql"|grep "socket=&q ...
随机推荐
- WCF技术剖析之二十八:自己动手获取元数据[附源代码下载]
原文:WCF技术剖析之二十八:自己动手获取元数据[附源代码下载] 元数据的发布方式决定了元数据的获取行为,WCF服务元数据架构体系通过ServiceMetadataBehavior实现了基于WS-ME ...
- 【译】在Asp.Net中操作PDF - iTextSharp - 利用列进行排版
原文 [译]在Asp.Net中操作PDF - iTextSharp - 利用列进行排版 在使用iTextSharp通过ASP.Net生成PDF的系列文章中,前面的文章已经讲述了iTextSharp所涵 ...
- UIView详解1
一个UIView的实例就是一个视图,表示的是屏幕上的一块矩形区域,负责这块矩形区域的描绘以及和用户的交互. 第一.UIView的可视化属性 1. backgroundColor 背景属性 2. hi ...
- CF 319C(Kalila and Dimna in the Logging Industry-斜率DP,注意叉积LL溢出)
C. Kalila and Dimna in the Logging Industry time limit per test 2 seconds memory limit per test 256 ...
- Hadoop 源码分析(二四)FSNamesystem
以下轮到FSNamesystem 出场了. FSNamesystem.java 一共同拥有4573 行.而整个namenode 文件夹下全部的Java 程序总共也仅仅有16876 行,把FSNames ...
- cocos2d-x on wp8架构简单介绍
1,基于C++的开发架构 支持3大移动平台以及3大桌面平台. 分为图形,声音,物理3大模块,另外还有脚本的导出. 在wp8/win32上的图形是基于d3d的,而在其它平台是基于opengl/openg ...
- C# - 线程操作
代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- C语言,C++,static
术语static有着不寻常的历史.起初,在C中引入关键字static是为了表示退出一个块后仍然存在的局部变量.随后,static在C中有了第二种含义:用来表示不能被其它文件访问的全局变量和函数.为了避 ...
- android保存文件到SD卡中
想把文件保存到SD卡中,一定要知道SD卡的路径,有人说可以用File explore来查看,这种方法不太好,因为随着android版本的升级,SD卡的路径可能会发生改变.在1.6的时候SD的路径是/s ...
- 4Sum -- LeetCode
原题链接: http://oj.leetcode.com/problems/4sum/ 这道题要求跟3Sum差点儿相同,仅仅是需求扩展到四个的数字的和了.我们还是能够依照3Sum中的解法,仅仅是在外 ...