ABAddressBook for transition to CNContact transition

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

How does everyone else handle this? I have not been in this situation before.

+5
source share
3 answers

I also dealt with this issue and studied this issue, what I decided to do as you suggest; check the iOS version for users by doing something like the following:

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

... continued based on the versions that you decide to support for your application.

Then I do a check to either use the Addressbook structure earlier than for iOS 9, and for the contact environment for iOS 9 and above.

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

This is the best way I could think to handle this depressing business ...

+4
source

Outdated does not mean removal. Just make the link to both structures optional and start creating a data workflow that can handle both structures. Also keep in mind that CNContact is new and full of bugs.

As soon as you think that your application is reorganized, and iOS - by 9.1, you will get a green light

How to find out if a system supports functionality

1) Check if class exists

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

For loosely coupled classes, it is safe to report this class directly. Remarkably, this works for frameworks that are clearly not related 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 application in the simulator to find the constant NSFoundationVersionNumber

+2
source
 if #available(iOS 9, *) { // iOS 9 - CNContact } else { // iOS 8 - ABAddressBook } 

This is the right way to check.

0
source

All Articles