I am working on an existing objective c project , While reading Address Book UI Framework Reference for iOS i found the below classes have deprecated in iOS 9 .
( ABUnknownPersonViewController
, ABPersonViewController
, ABPeoplePickerNavigationController
, ABNewPersonViewController
)
What is the replacement of this .? Where i can find some document related this . any help appreciated . Thanks in advance .

- 1,311
- 1
- 14
- 42

- 1,616
- 3
- 22
- 40
2 Answers
The AddressBookUI
framework has been deprecated in iOS 9
, so better you should use ContactsUI
Framework.
It has many new features including all the features of AddressBookUI
framework.
So, in case if you are targeting the iOS 9
specifically then you should go for ContactsUI
Framework.
To check that AddressBookUI
framework is available for specific iOS
version you can do the following:
if ([CNContactStore class]) {
CNContactStore *store = [CNContactStore new];
//...
} else {
// Fallback to old framework
}
Here is the complete code for that:
- (void) contactScan
{
if ([CNContactStore class]) {
//ios9 or later
CNEntityType entityType = CNEntityTypeContacts;
if( [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusNotDetermined)
{
CNContactStore * contactStore = [[CNContactStore alloc] init];
[contactStore requestAccessForEntityType:entityType completionHandler:^(BOOL granted, NSError * _Nullable error) {
if(granted){
[self getAllContact];
}
}];
}
else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized)
{
[self getAllContact];
}
}
}
-(void)getAllContact
{
if([CNContactStore class])
{
//iOS 9 or later
NSError* contactError;
CNContactStore* addressBook = [[CNContactStore alloc]init];
[addressBook containersMatchingPredicate:[CNContainer predicateForContainersWithIdentifiers: @[addressBook.defaultContainerIdentifier]] error:&contactError];
NSArray * keysToFetch =@[CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey];
CNContactFetchRequest * request = [[CNContactFetchRequest alloc]initWithKeysToFetch:keysToFetch];
BOOL success = [addressBook enumerateContactsWithFetchRequest:request error:&contactError usingBlock:^(CNContact * __nonnull contact, BOOL * __nonnull stop){
[self parseContactWithContact:contact];
}];
}
}
- (void)parseContactWithContact :(CNContact* )contact
{
NSString * firstName = contact.givenName;
NSString * lastName = contact.familyName;
NSString * phone = [[contact.phoneNumbers valueForKey:@"value"] valueForKey:@"digits"];
NSStrubg * email = [contact.emailAddresses valueForKey:@"value"];
NSArray * addrArr = [self parseAddressWithContac:contact];
}
- (NSMutableArray *)parseAddressWithContac: (CNContact *)contact
{
NSMutableArray * addrArr = [[NSMutableArray alloc]init];
CNPostalAddressFormatter * formatter = [[CNPostalAddressFormatter alloc]init];
NSArray * addresses = (NSArray*)[contact.postalAddresses valueForKey:@"value"];
if (addresses.count > 0) {
for (CNPostalAddress* address in addresses) {
[addrArr addObject:[formatter stringFromPostalAddress:address]];
}
}
return addrArr;
}
Just make sure that you ask the permission to read the contacts from device.
Reference link: https://gist.github.com/willthink/024f1394474e70904728
Updated:
For replacement for AddressBookUI
you need to use CNContactPickerViewController
. You can check the delegate methods which can be used to pickup the one or multiple contacts at a time.
This will present a inbuilt UIViewController
with all the contacts and you need to implement the delegate methods of it!
To select one contact:
contactPicker:didSelectContact:
To select multiple (New Feature):
contactPicker:didSelectContacts:
CNContactPickerDelegate
reference: https://developer.apple.com/library/ios/documentation/ContactsUI/Reference/CNContactPickerDelegate_Protocol/

- 9,404
- 1
- 31
- 57
-
I am assuming ContactsUI won't be available for <9.0 iOS versions? Let's suppose I am targeting iOS 7 and above. How do you suppose I should tackle it? (Since I am getting deprecated warning for methods using AddressBook Framework\ – NSNoob Jan 29 '16 at 07:23
-
Yes, you should tackle that method using the above code `if ([CNContactStore class]) { CNContactStore *store = [CNContactStore new]; //... } else { // Fallback to old framework }` – Sohil R. Memon Jan 29 '16 at 07:25
-
1But falling back to old method will still retain the deprecated warning in my project. What's the incentive of moving to ContactsUI then? – NSNoob Jan 29 '16 at 07:26
-
The advantage is `AddressBookUI` is unavailable in `iOS 9`, so there you must be use `ContactsUI` and if you running on earlier version then you must be using `AddressBookUI` there `ContactsUI` will not be available. P.S. The deprecated warning will be there! – Sohil R. Memon Jan 29 '16 at 07:29
-
1Not really. Even though it is deprecated, `AddressBookUI` is still working for iOS 9 in my App. Thank you anyways. – NSNoob Jan 29 '16 at 07:33
-
Yes it will be! But as the method are deprecated the Apple can stop support for it! So, the only option is to use the `ContactsUI` – Sohil R. Memon Jan 29 '16 at 07:36
-
1I believe that if you specify a deployment target of less than iOS 9.0, Xcode will stop warning you about the deprecation? Happens for other deprecated methods/classes etc. – Nicolas Miari Jan 29 '16 at 08:14
-
1@Rob I have updated the answer. Thanks for spotting me out! – Sohil R. Memon Jan 29 '16 at 08:55
-
How about the view for creating a new contact? Should I use this? ``init(forUnknownContact contact: CNContact)`` and then the user can add the contact? The problem it's I have 2 steps before creating a contact. – gzfrancisco Sep 22 '16 at 22:20
Apple has introduced new framework for this for iOS9 and above please fine below link Link
Edit: one more link :Link2

- 1,311
- 1
- 14
- 42
-
1Please avoid link-only answers. At the very least you should mention the name of the new framework (in this case, `ContactsUI`) so that if the links break in the future, someone reading the answer can at least search it by name. – Nicolas Miari Jan 29 '16 at 08:15