iOS 7.0
JLAddressBook is available through CocoaPods, to install it simply add the following line to your Podfile:
pod "JLAddressBook"
To run the example project; clone the repo, run pod install
, then open JLAddressBookExample.xcworkspace.
All you need to do is create an entity type that conforms to this protocol
@protocol JLContact<NSObject>
@optional
@property(nonatomic, strong) NSString *firstName;
@property(nonatomic, strong) NSString *lastName;
@property(nonatomic, strong) NSArray *phoneNumbers; // NSString's
@property(nonatomic, strong) NSArray *emails; // NSString's
@property(nonatomic, strong) NSArray *addressBookIDs; // NSNumbers's
@property(nonatomic, strong) UIImage *thumbnail;
@property(nonatomic, strong) UIImage *photo;
@end
and then use the JLCoreDataContactManager or define a contact manager to keep track of these entities yourself:
@protocol JLContactManager<NSObject>
@required
- (id<JLContact>)newContact;
- (NSArray *)existingContacts;
@end
then you call JLAddressBook syncContacts to update your contacts from the iphone address book
@interface JLAddressBook : NSObject
- (instancetype)initWithContactManager:(id<JLContactManager>)contactManager;
+ (BOOL)authorized;
+ (void)attemptToAuthorize:(AuthorizationBlock)block;
- (NSArray *)syncContacts;
- (UIImage *)photoForContact:(id<JLContact>)contact;
- (UIImage *)thumbnailForContact:(id<JLContact>)contact;
- (void)addContactToDevice:(id<JLContact>)contact;
- (void)addContactToDevice:(id<JLContact>)contact withPhoto:(UIImage *)photo;
@end
Here is a list of iPhone apps utilizing this library:
JLAddressBook is available under the MIT license. See the LICENSE file for more info.