Example
Importing the framework
Swift
import Contacts
Objective-C
#import <Contacts/Contacts.h>
Checking accessibility
Swift
switch CNContactStore.authorizationStatusForEntityType(CNEntityType.Contacts){
case .Authorized: //access contacts
case .Denied, .NotDetermined: //request permission
default: break
}
Objective-C
switch ([CNContactStore authorizationStatusForEntityType:CNEntityType.Contacts]){
case CNAuthorizationStatus.Authorized:
//access contacts
break;
case CNAuthorizationStatus.Denied:
//request permission
break;
case CNAuthorizationStatus.NotDetermined:
//request permission
break;
}
Requesting Permission
Swift
var contactStore = CKContactStore()
contactStore.requestAccessForEntityType(CKEntityType.Contacts, completionHandler: { (ok, _) -> Void in
if access{
//access contacts
}
}