Authorizing Contact Access

suggest change

Importing the framework

Swift

import Contacts

Objective-C

#import <Contacts/Contacts.h>

Checking accessibility

Swift

switch CNContactStore.authorizationStatusForEntityType(CNEntityType.Contacts) {
case .Authorized:
    break // access contacts
case .NotDetermined:
    break // request permission; the prompt is shown only in this state
case .Denied, .Restricted:
    break // the system will not show the prompt again
}

Objective-C

switch ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]) {
case CNAuthorizationStatusAuthorized:
    // access contacts
    break;
case CNAuthorizationStatusNotDetermined:
    // request permission; the prompt is shown only in this state
    break;
case CNAuthorizationStatusDenied:
case CNAuthorizationStatusRestricted:
    // the system will not show the prompt again
    break;
}

Requesting Permission

Swift

let contactStore = CNContactStore()
contactStore.requestAccessForEntityType(CNEntityType.Contacts, completionHandler: { granted, error in
    if granted {
        // access contacts
    }
})

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents