diff --git a/APAddressBook.podspec b/APAddressBook.podspec new file mode 100644 index 0000000..4c5269e --- /dev/null +++ b/APAddressBook.podspec @@ -0,0 +1,14 @@ +Pod::Spec.new do |s| + s.name = "APAddressBook" + s.version = "0.0.1" + s.summary = "Easy access to iOS address book" + s.homepage = "https://github.com/Alterplay/APAddressBook" + s.license = { :type => 'MIT', :file => 'LICENSE.txt' } + s.author = { "Alexey Belkevich" => "alexey.belkevich@alterplay.com" } + s.source = { :git => "https://github.com/Alterplay/APAddressBook.git", + :tag => s.version.to_s } + s.source_files = 'Classes/**/*.{h,m}' + s.ios.deployment_target = "5.0" + s.requires_arc = true + s.frameworks = 'AddressBook' +end diff --git a/Classes/APTypes.h b/Classes/APTypes.h index 4cef5be..e71ddd2 100644 --- a/Classes/APTypes.h +++ b/Classes/APTypes.h @@ -29,7 +29,7 @@ typedef enum APContactFieldEmails = 1 << 4, APContactFieldPhoto = 1 << 5, APContactFieldDefault = APContactFieldFirstName | APContactFieldLastName | - APContactFieldPhones, + APContactFieldPhones, APContactFieldAll = APContactFieldDefault | APContactFieldCompany | APContactFieldEmails | APContactFieldPhoto } APContactField; diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..475597b --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright (c) 2013 Alterplay + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 6fef8a4..25216c7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,105 @@ APAddressBook -============= +============ + +#### About +APAddressBook is a wrapper on [AddressBook.framework](https://developer.apple.com/library/ios/documentation/AddressBook/Reference/AddressBook_iPhoneOS_Framework/_index.html) + +--- + +#### Features +* Load contacts from iOS address book asynchronously +* Decide what contact data fields you need to load (for example, only first name and phone number) +* Filter contacts to get only necessary records (for example, you need only contacts with email) +* Sort contacts with array of any [NSSortDescriptor](https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/NSSortDescriptor_Class/Reference/Reference.html) + +#### Installation +Add `APAddressBook` pod to Podfile + +--- + +#### Using + +###### Load contacts +```objective-c +APAddressBook *addressBook = [[APAddressBook alloc] init]; +// don't forget to show some activity +[addressBook loadContacts:^(NSArray *contacts, NSError *error) +{ + // hide activity + if (!error) + { + // do something with contacts array + } + else + { + // show error + } +}]; +``` + +--- + +###### Select contact fields bit-mask +Available fields: +* APContactFieldFirstName - *contact first name* +* APContactFieldLastName - *contact last name* +* APContactFieldCompany - *contact company (organisation)* +* APContactFieldPhones - *contact phones array* +* APContactFieldEmails - *contact emails array* +* APContactFieldPhoto - *contact photo* +* APContactFieldDefault - *contact first name, last name and phones array* +* APContactFieldAll - *all contact fields described above* + +Example of loading contact with first name and photo: +```objective-c +APAddressBook *addressBook = [[APAddressBook alloc] init]; +addressBook.fieldsMask = APContactFieldFirstName | APContactFieldPhoto; +``` + +--- + +###### Filter contacts +The most common use of this option is to filter contacts without phone number +Example: +```objective-c +addressBook.filterBlock = ^BOOL(APContact *contact) +{ + return contact.phones.count > 0; +}; +``` + +--- + +###### Sort contacts +APAddressBook returns unsorted contacts. So, most of users would like to sort contacts by first name and last name. +```objective-c +addressBook.sortDescriptors = @[ + [NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES], + [NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES] +]; +``` + +###### Check address book access +```objective-c +switch([APAddressBook access]) +{ + case APAddressBookAccessUnknown: + // Application didn't request address book access yet + break; + + case APAddressBookAccessGranted: + // Access granted + break; + + case APAddressBookAccessDenied: + // Access denied or restricted by privacy settings + break; +} +``` + +--- + +#### Contacts + +[Check out](https://github.com/Alterplay) all Alterplay's GitHub projects. +[Email us](mailto:hello@alterplay.com?subject=From%20GitHub%20APAddressBook) with other ideas and projects.