Ich versuche, mit dem folgenden Code auf die Kontakte des Telefons zuzugreifen, aber der Benutzer wird nicht aufgefordert, mir die Erlaubnis zu geben.requestAccessForEntityType keine Benutzeranfrage
let store = CNContactStore()
store.requestAccessForEntityType(.Contacts) { granted, error in
guard granted else {
dispatch_async(dispatch_get_main_queue()) {
// user didn't grant authorization, so tell them to fix that in settings
print("error accessing adress book %@",error)
}
return
}
print("Access granted to adress book")
// get the contacts
var contacts = [CNContact]()
let request = CNContactFetchRequest(keysToFetch: [CNContactIdentifierKey, CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName)])
do {
try store.enumerateContactsWithFetchRequest(request) { contact, stop in
contacts.append(contact)
}
} catch {
print(error)
}
//TODO : Do something with the contacts
let formatter = CNContactFormatter()
formatter.style = .FullName
for contact in contacts {
print(formatter.stringFromContact(contact))
}
}