How to access contacts in iOS 6 and later? I think it needs some permission . Could anyone tell me how to request for permission programmatically?
Asked
Active
Viewed 2,883 times
1
-
http://stackoverflow.com/questions/12648244/programmatically-request-access-to-contacts-in-ios-6 – rptwsthi Feb 18 '13 at 13:37
-
for iOS 9 and above http://stackoverflow.com/a/39374916/569789 – Zaraki Sep 07 '16 at 16:21
2 Answers
4
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
if (granted) {
NSLog(@"Access granted!");
} else {
NSLog(@"Access denied!");
}
});
}
Edit:
This answer is a little bit more detailed: https://stackoverflow.com/a/12648938/322548

Community
- 1
- 1

Fabian Kreiser
- 8,307
- 1
- 34
- 60
0
iOS will ask the user for remission as soon as you try to access the address book from code.
There is no way for you to ask permission since iOS will handle this for you.
You can check the status of permission with the ABAddressBookGetAuthorizationStatus
method, you will need to add the AddressBook.framework
to you project and add #import <AddressBook/AddressBook.h>
to the .h
or .m
file where you want to use the method.
ABAuthorizationStatus status = ABAddressBookGetAuthorizationStatus();
if(status == kABAuthorizationStatusDenied) {
// User has reject your request to access the address book
}

rckoenes
- 69,092
- 8
- 134
- 166
-
This is wrong. You should request access to the address book before using it on iOS 6. – Fabian Kreiser Feb 18 '13 at 13:37
-
Not wrong if you only use the `AddressBookUI.framework` you can just open the `ABPeoplePickerNavigationController` and it will request access for you.\ – rckoenes Feb 18 '13 at 13:40
-
2Yeah, but the OP wanted to know how to request the access when you're accessing the address book programmatically without `AddressBookUI`: `Could anyone tell me how to request for permission programmatically?` – Fabian Kreiser Feb 18 '13 at 13:42