CNContactStore.requestAccessForEntityType参数问题

时间:2015-09-11 15:28:10

标签: swift

我正在尝试使用CNContactStore函数requestAccessForEntityType获得使用地址簿的授权,但我收到了一个我不理解的错误。

该功能在类中定义为:

public func requestAccessForEntityType(entityType: CNEntityType, completionHandler: (Bool, NSError?) -> Void)

这是我的代码:

let addressBookRef: CNContactStore = CNContactStore.requestAccessForEntityType(CNEntityType.Contacts, completionHandler: authorizationHandler)

func authorizationHandler(granted: Bool, error: NSError?) {

}

编译错误:

  

调用

中的额外参数'completionHandler'

1 个答案:

答案 0 :(得分:0)

原来我直接在课堂上定义了这个属性。显然你不能在那里运行一个功能,所以它不起作用。杜!

我需要做的就是上课:

let addressBookRef = CNContactStore()

以下是实际请求许可的时候:

addressBookRef.requestAccessForEntityType(CNEntityType.Contacts, completionHandler: authorizationHandler)