Mika
Mika

Reputation: 5845

CNContactStore.requestAccessForEntityType argument issue

I am trying to get authorisation to use the addressbook using the CNContactStore function requestAccessForEntityType but I get an error I don't understand.

The function is defined in the class as:

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

This is my code:

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

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

}

Compiler error:

Extra argument 'completionHandler' in call

Upvotes: 1

Views: 1671

Answers (1)

Mika
Mika

Reputation: 5845

Turns out that I was defining the property directly in the class. Obviously you can't run a function there and so it was not working. Duh!

All I need to do was put in the class:

let addressBookRef = CNContactStore()

And the following when it was time to actually ask for permission:

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

Upvotes: 1

Related Questions