Latest 1.0.5
Homepage https://github.com/mostachoio/MoABContactsManager
License MIT
Platforms ios 6.0, requires ARC
Authors

Build Status
Version
License
Platform

Installation

MoABContactsManager is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "MoABContactsManager"

Basic Usage

Get all contacts

[[MoABContactsManager sharedManager] contacts:^(ABAuthorizationStatus authorizationStatus, NSArray *contacts, NSError *error) {

    if (error) {
        // An error has ocurred
    }else {
        if (authorizationStatus == kABAuthorizationStatusAuthorized) {
            // Do something with contacts
        }else {
            // User didn't give permissions
        }
    }

}];

Create contact

[[MoABContactsManager sharedManager] addContact:contact completion:^(NSError *error) {
    // Do sometihng
}];

Update contact

[[MoABContactsManager sharedManager] updateContact:contact completion:^(NSError *error) {
    // Do something
}];

Delete contact

[[MoABContactsManager sharedManager] deleteContactWithId:contact.contactId completion:^(NSError *error) {
    // Do something
}];

Advanced Usage

Use sort descriptor

[[MoABContactsManager sharedManager] setSortDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"fullName" ascending:YES]]];

Filter contacts

// Set MoABContactsManager delegate
[[MoABContactsManager sharedManager] setDelegate:self];

// Implement delegate
- (BOOL)moABContatsManager:(MoABContactsManager *)contactsManager shouldIncludeContact:(MoContact *)contact
{
    // Only show contacts with phones
    return [contact.phones count] > 0;
}

Select contacts fields to fetch

[[MoABContactsManager sharedManager] setFieldsMask:MoContactFieldFirstName | MoContactFieldLastName | MoContactFieldEmails | MoContactFieldPhones | MoContactFieldThumbnailProfilePicture];

Serialize Contacts

NSLog(@"Serialized Contact: %@", [contact asDictionary]);

Output:

{
    "contact_id" = 888;
    "emails" =
            (
                {
                    "work" = "[email protected]"
                },
                {
                    "home" = "[email protected]"
                }
            );
    "emails_values" =     
                    (
                        "[email protected]",
                        "[email protected]"
                    );
    "first_name" = John;
    "last_name" = Doe;
    "full_name" = "John Doe";
    "phones" =    
            (
                {
                    "mobile" = "+13121123345"    
                }
            );
    "phones_values" =     
                    (
                        "+13121123345"
                    )
    "addresses" =     
                (
                    {
                        "work" = 
                                {
                                    "City" = "Cupertino",
                                    "Country" = "United States",
                                    "CountryCode" = "us",
                                    "State" = "CA",
                                    "Street" = "1 Infinite Loop",
                                    "ZIP" = "95014"
                                }
                    }
                )
}

What’s next?

  • Handle linked contacts

Author

Diego Pais

License

MoABContactsManager is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "MoABContactsManager",
    "version": "1.0.5",
    "summary": "Simple address book contacts manager.",
    "description": "                      MoABContactsManager is a wrapper of AddressBook.framework which allows you to get, create, update or delete contacts in an easy way.n",
    "homepage": "https://github.com/mostachoio/MoABContactsManager",
    "license": "MIT",
    "authors": {
        "Diego Pais": "[email protected]"
    },
    "source": {
        "git": "https://github.com/mostachoio/MoABContactsManager.git",
        "tag": "1.0.5"
    },
    "platforms": {
        "ios": "6.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "MoABContactsManager": [
            "Pod/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This