Latest 2.1.2
Homepage https://github.com/Serjip/ContactsKit
License MIT
Platforms ios 6.0, osx 10.7, requires ARC
Authors

ContactsKit

ContactsKit is a library for easy contact management supports iOS and Mac OS X.

Features

  • Unifying linked contacts
  • Support Mac OS X
  • Contact management add, update, delete
  • Support NSCoding
  • Observing changes (adding, updating, deleting) for iOS

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like ContactsKit in your projects. See more on cocoapods.org. You can install it with the following command:

$ gem install cocoapods

Podfile

To integrate ContactsKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'

pod 'ContactsKit'

Then, run the following command:

$ pod install

Get started

Import ContactsKit into your porject


    #import <ContactsKit/ContactsKit.h>

Firstly you have to create an instance of the CKAddressBook, and request an access for getting contacts.
The user will only be prompted the first time access is requested.


    CKAddressBook *addressBook = [[CKAddressBook alloc] init];

    [addressBook requestAccessWithCompletion:^(NSError *error) {

        if (! error)
        {
            // Everything fine you can get contacts
        }
        else
        {
            // The app doesn't have a permission for getting contacts
            // You have to go to the settings and turn on contacts
        }
    }];

Then if the access is granted you can get contacts


    // Get fields from the mask
    CKContactField mask = CKContactFieldFirstName | CKContactFieldLastName | CKContactFieldBirthday;

    // Final sort of the contacts array
    NSArray *sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES] ];

    [addressBook contactsWithMask:mask uinify:NO sortDescriptors:sortDescriptors
                           filter:nil completion:^(NSArray *contacts, NSError *error) {

        if (! error)
        {
            // Do someting with contacts
        }

    }];

Or do the same by using the CKAddressBookDelegate protocol


    addressBook.fieldsMask = CKContactFieldFirstName | CKContactFieldLastName | CKContactFieldBirthday;
    addressBook.sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES] ];
    addressBook.delegate = self;

    [addressBook fetchContacts];

Then the protocol method will called


    #pragma mark - CKAddressBookDelegate

    - (void)addressBook:(CKAddressBook *)addressBook didFetchContacts:(NSArray<CKContact *> *)contacts
    {
        // Do something with contacts
    }

Latest podspec

{
    "name": "ContactsKit",
    "version": "2.1.2",
    "summary": "Contacts management without headache",
    "homepage": "https://github.com/Serjip/ContactsKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE.txt"
    },
    "authors": {
        "Sergey Popov": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Serjip/ContactsKit.git",
        "tag": "2.1.2"
    },
    "requires_arc": true,
    "resources": "ContactsKit/ContactsKit.bundle",
    "source_files": "ContactsKit/**/*.{h,m}",
    "public_header_files": "ContactsKit/Public/*.h",
    "ios": {
        "frameworks": "AddressBook"
    },
    "platforms": {
        "ios": "6.0",
        "osx": "10.7"
    },
    "osx": {
        "frameworks": "AddressBook"
    }
}

Pin It on Pinterest

Share This