Search code examples
ios8ios9addressbookcontacts-framework

AddressBook and Contacts framework in iOS 8.0 and 9.0


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!


Solution

  • 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
    }