swift - 如何在 Swift iOS 8 中使用 requestAccessToEntityType 方法

标签 swift ios8 eventkit ekeventstore

我正在尝试通过在 iOS8 中使用 Swift 使用 EKEventStore 获取事件列表,据我所知,文档尚未更新。

这就是我想要做的:

let eventStore =  EKEventStore()

eventStore.requestAccessToEntityType(EKEntityType(), EKEventStoreRequestAccessCompletionHandler(Bool(), NSError(){}))

这是我得到的错误:

“EKEventStoreRequestAccessCompletionHandler”不能用“(Bool, NSError)”构造

您知道如何在 Swift 中正确使用方法或处理程序吗?

最佳答案

请试试这个:

func handler(granted: Bool, error: NSError!) {
    // put your handler code here
}

@IBAction func click(sender: AnyObject) {
    let eventStore = EKEventStore()

    // 'EKEntityTypeReminder' or 'EKEntityTypeEvent'
    eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: handler) 
}

另一种变体是:

@IBAction func click(sender: AnyObject) {
    let eventStore = EKEventStore()

    // 'EKEntityTypeReminder' or 'EKEntityTypeEvent'
    eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: {
        granted, error in

        // put your handler code here
        })
}

关于swift - 如何在 Swift iOS 8 中使用 requestAccessToEntityType 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24692605/

相关文章:

swift - 3D Touch 和 UITableViewCell

ios - "Fixed"奇怪的 "unrecognized selector sent to instance"崩溃发生在 iOS8 beta5

ios - PHAsset 获取原始文件名

iOS:使用不可编辑的事件创建日历?

ios - 访问 "Events Found in Mail"日历中的事件

generics - Swift - 如何将此方法推广到我的父类(super class)中?

xcode - 如何在 Swift 中设置 collectionview 单元格之间的间距?

json - 重新加载数据CollectionView

ios - 使用 EXC_RESOURCE 关闭应用程序,iOS 8 GM 上的 WAKEUPS 异常

swift - 如何打开带有事件的日历 - NSURL calshow :