加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 04:39:18 所属栏目:百科 来源:网络整理
导读:我试图通过在iOS8中使用 Swift使用EKEventStore获取事件列表,据我所知,文档尚未更新. 这就是我想要做的: let eventStore = EKEventStore()eventStore.requestAccessToEntityType(EKEntityType(),EKEventStoreRequestAccessCompletionHandler(Bool(),NSError
我试图通过在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
        })
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读