Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ABAddressBook to CNContact App Transition

I am working on an app that is close to launch but uses the ABAddressBook framework. With the deprecation of ABAddressBook in iOS9, do I need to check the user's iOS version, and use ABAddressBook for pre iOS9 users, and CNContact for iOS9 users?

How is everyone else handling this? I haven't been in a situation like this before.

like image 270
Felker Avatar asked Aug 14 '15 06:08

Felker


2 Answers

I have also been dealing-with and researching this issue, what I've opted to do is as you suggest; check the users iOS version doing something like the following:

NSString *version = [[UIDevice currentDevice] systemVersion];
BOOL isVersion8 = [version hasPrefix:@"8."];
BOOL isVersion7 = [version hasPrefix:@"7."];
//...

...continuing based on the versions you've decided to support for your app.

Then I do a check to either use the Addressbook framework for earlier than iOS 9, and Contacts framework for iOS 9 and beyond.

if(isVersion7 || isVersion8){
    //Use AddressBook
   }
else{
    //Use Contacts
}

That's the best way I could think to deal with this deprecation business...

like image 93
UberJames Avatar answered Nov 14 '22 18:11

UberJames


Deprecated doesn't mean removed. Just make linking to both frameworks as optional and start to design data workflow that can handle both frameworks. Also please mind that CNContact is new and full of bugs.

Once you think your app is refactored and iOS evolved to 9.1 give it a green light

How to know if system supports functionality

1) Check if the class exists

if(NSClassFromString(@"CNContact")) {
    // Do something
}

For weakly linked classes, it is safe to message the class, directly. Notably, this works for frameworks that aren't explicitly linked as "Required". For missing classes, the expression evaluates to nil.

2)

#ifned NSFoundationVersionNumber_iOS_9 
 #def NSFoundationVersionNumber_iOS_9 NUMBER
#endif

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9) {
   // Use address book
} else {
   // Use contact framework
}

Run the app in simulator to find the NSFoundationVersionNumber constant

like image 41
Marek H Avatar answered Nov 14 '22 20:11

Marek H