3

I am trying to build an app that fetches contact list from users contacts and renders it in Custom UI of app. I want to support iOS 8 and iOS9 But the problem is methods of AddressBook framework are deprecated in iOS9 and Contacts Framework will not support iOS 8.0. Is there's a way I can support both 8 & 9 for this?

Thanks in Advance!

user3401744
  • 33
  • 1
  • 5

2 Answers2

5

You have to implement both the code, if you want to support both iOS versions.

You have to check for iOS versions as below, for Objective-C

NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"9.0" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending) {
    // OS version >= 9.0
    // Call contact address book function
} else {
    // OS version < 9.0
    // Call address book function
}

For swift,

if #available(iOS 9.0, *) {
    // OS version >= 9.0
    // Call contact address book function
} else {
    // OS version < 9.0
    // Call address book function
}
Varun
  • 759
  • 6
  • 12
  • any other approach we can use? I dnt want to write same code twice. – user3401744 Feb 10 '16 at 09:23
  • There is one way. If you are supporting iOS 8 and above, you can make use of ABAddressBook. It'll work in iOS 9 too. But when you remove iOS 8 support in future, you have to replace ABAddressBook with CNContactStore. Personally I would prefer writing both codes with future in mind. – Varun Feb 10 '16 at 16:06
3

Besides checking for iOS 8 and iOS 9 to call functions,

make sure the framework that's not available on iOS 8 is set as Optional

enter image description here

Ted
  • 22,696
  • 11
  • 95
  • 109