Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 135 additions & 17 deletions ABContact.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,103 @@
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>


#pragma mark - Human Readable Name Strings for Dictionary Conversion

#define FIRST_NAME_STRING @"First Name"
#define MIDDLE_NAME_STRING @"Middle Name"
#define LAST_NAME_STRING @"Last Name"

#define PREFIX_STRING @"Prefix"
#define SUFFIX_STRING @"Suffix"
#define NICKNAME_STRING @"Nickname"

#define PHONETIC_FIRST_STRING @"Phonetic First Name"
#define PHONETIC_MIDDLE_STRING @"Phonetic Middle Name"
#define PHONETIC_LAST_STRING @"Phonetic Last Name"

#define ORGANIZATION_STRING @"Organization"
#define JOBTITLE_STRING @"Job Title"
#define DEPARTMENT_STRING @"Department"

#define NOTE_STRING @"Note"

#define BIRTHDAY_STRING @"Birthday"
#define CREATION_DATE_STRING @"Creation Date"
#define MODIFICATION_DATE_STRING @"Modification Date"

#define KIND_STRING @"Kind"

#define EMAIL_STRING @"Email"
#define ADDRESS_STRING @"Address"
#define DATE_STRING @"Date"
#define PHONE_STRING @"Phone"
#define IM_STRING @"Instant Message"
#define URL_STRING @"URL"
#define RELATED_STRING @"Related Name"
#define SOCIAL_STRING @"Social Profile"

#define IMAGE_STRING @"Image"

#pragma mark Label Quick Reference

/*
// Generic
const CFStringRef kABWorkLabel;
const CFStringRef kABHomeLabel;
const CFStringRef kABOtherLabel;

// Relation
const CFStringRef kABPersonMotherLabel;
const CFStringRef kABPersonFatherLabel;
const CFStringRef kABPersonParentLabel;
const CFStringRef kABPersonSisterLabel;
const CFStringRef kABPersonBrotherLabel;
const CFStringRef kABPersonChildLabel;
const CFStringRef kABPersonFriendLabel;
const CFStringRef kABPersonSpouseLabel;
const CFStringRef kABPersonPartnerLabel;
const CFStringRef kABPersonManagerLabel;
const CFStringRef kABPersonAssistantLabel;

// URL
const CFStringRef kABPersonHomePageLabel;

// Social
const CFStringRef kABPersonSocialProfileServiceTwitter;
const CFStringRef kABPersonSocialProfileServiceGameCenter;
const CFStringRef kABPersonSocialProfileServiceFacebook;
const CFStringRef kABPersonSocialProfileServiceMyspace;
const CFStringRef kABPersonSocialProfileServiceLinkedIn;
const CFStringRef kABPersonSocialProfileServiceFlickr;

// IM
const CFStringRef kABPersonInstantMessageServiceYahoo;
const CFStringRef kABPersonInstantMessageServiceJabber;
const CFStringRef kABPersonInstantMessageServiceMSN;
const CFStringRef kABPersonInstantMessageServiceICQ;
const CFStringRef kABPersonInstantMessageServiceAIM;
const CFStringRef kABPersonInstantMessageServiceFacebook;
const CFStringRef kABPersonInstantMessageServiceGaduGadu;
const CFStringRef kABPersonInstantMessageServiceGoogleTalk;
const CFStringRef kABPersonInstantMessageServiceQQ;
const CFStringRef kABPersonInstantMessageServiceSkype;

// Phone Numbers
const CFStringRef kABPersonPhoneMobileLabel;
const CFStringRef kABPersonPhoneIPhoneLabel;
const CFStringRef kABPersonPhoneMainLabel;
const CFStringRef kABPersonPhoneHomeFAXLabel;
const CFStringRef kABPersonPhoneWorkFAXLabel;
const CFStringRef kABPersonPhonePagerLabel;
const CFStringRef kABPersonPhoneOtherFAXLabel;

// Date
const CFStringRef kABPersonAnniversaryLabel;
*/

#pragma mark ABContact

@interface ABContact : NSObject
{
ABRecordRef record;
Expand All @@ -23,20 +120,39 @@
+ (ABPropertyType) propertyType: (ABPropertyID) aProperty;
+ (NSString *) propertyTypeString: (ABPropertyID) aProperty;
+ (NSString *) propertyString: (ABPropertyID) aProperty;
+ (BOOL) propertyIsMultivalue: (ABPropertyID) aProperty;
+ (BOOL) propertyIsMultiValue: (ABPropertyID) aProperty;
+ (NSArray *) arrayForProperty: (ABPropertyID) anID inRecord: (ABRecordRef) record;
+ (id) objectForProperty: (ABPropertyID) anID inRecord: (ABRecordRef) record;

// Creating proper dictionaries
+ (NSDictionary *) dictionaryWithValue: (id) value andLabel: (CFStringRef) label;
+ (NSDictionary *) addressWithStreet: (NSString *) street withCity: (NSString *) city
withState:(NSString *) state withZip: (NSString *) zip
withCountry: (NSString *) country withCode: (NSString *) code;
+ (NSDictionary *) smsWithService: (CFStringRef) service andUser: (NSString *) userName;
+ (BOOL) isMultivalueDictionary: (NSDictionary *) dictionary;
+ (NSDictionary *) addressWithStreet: (NSString *) street withCity: (NSString *) city withState:(NSString *) state withZip: (NSString *) zip withCountry: (NSString *) country withCode: (NSString *) code;
+ (NSDictionary *) imWithService: (CFStringRef) service andUser: (NSString *) userName;
+ (NSDictionary *) socialWithURL: (NSString *) url withService: (NSString *) serviceName withUsername: (NSString *) username withIdentifier: (NSString *) key;

// Instance utility methods
- (BOOL) removeSelfFromAddressBook: (NSError **) error;

- (BOOL) addAddress: (NSDictionary *) dictionary;
- (BOOL) addAddressItem:(NSDictionary *)dictionary withLabel: (CFStringRef) label;
- (BOOL) addSocial: (NSDictionary *) dictionary;
- (BOOL) addSocialItem: (NSDictionary *) dictionary withLabel: (CFStringRef) label;
- (BOOL) addIM: (NSDictionary *) dictionary;
- (BOOL) addIMItem:(NSDictionary *)dictionary withLabel: (CFStringRef) label;

- (BOOL) addEmail: (NSDictionary *) dictionary;
- (BOOL) addEmailItem: (NSString *) value withLabel: (CFStringRef) label;
- (BOOL) addPhone: (NSDictionary *) dictionary;
- (BOOL) addPhoneItem: (NSString *) value withLabel: (CFStringRef) label;
- (BOOL) addURL: (NSDictionary *) dictionary;
- (BOOL) addURLItem: (NSString *) value withLabel: (CFStringRef) label;

// Sorting
- (BOOL) isEqualToString: (ABContact *) aContact;
- (NSComparisonResult) caseInsensitiveCompare: (ABContact *) aContact;

#pragma mark RECORD ACCESS
@property (nonatomic, readonly) ABRecordRef record;
@property (nonatomic, readonly) ABRecordID recordID;
@property (nonatomic, readonly) ABRecordType recordType;
Expand Down Expand Up @@ -68,8 +184,10 @@
@property (nonatomic, readonly) NSDate *creationDate;
@property (nonatomic, readonly) NSDate *modificationDate;

#pragma mark IMAGES
@property (nonatomic, assign) UIImage *image;

#pragma mark MULTIVALUE
// Each of these produces an array of NSStrings
@property (nonatomic, readonly) NSArray *emailArray;
@property (nonatomic, readonly) NSArray *emailLabels;
@property (nonatomic, readonly) NSArray *phoneArray;
Expand All @@ -82,9 +200,12 @@
@property (nonatomic, readonly) NSArray *dateLabels;
@property (nonatomic, readonly) NSArray *addressArray;
@property (nonatomic, readonly) NSArray *addressLabels;
@property (nonatomic, readonly) NSArray *smsArray;
@property (nonatomic, readonly) NSArray *smsLabels;
@property (nonatomic, readonly) NSArray *imArray;
@property (nonatomic, readonly) NSArray *imLabels;
@property (nonatomic, readonly) NSArray *socialArray;
@property (nonatomic, readonly) NSArray *socialLabels;

// Each of these produces an array of strings
@property (nonatomic, readonly) NSString *emailaddresses;
@property (nonatomic, readonly) NSString *phonenumbers;
@property (nonatomic, readonly) NSString *urls;
Expand All @@ -96,20 +217,17 @@
@property (nonatomic, assign) NSArray *urlDictionaries;
@property (nonatomic, assign) NSArray *dateDictionaries;
@property (nonatomic, assign) NSArray *addressDictionaries;
@property (nonatomic, assign) NSArray *smsDictionaries;

#pragma mark IMAGES
@property (nonatomic, assign) UIImage *image;
@property (nonatomic, assign) NSArray *imDictionaries;
@property (nonatomic, assign) NSArray *socialDictionaries;

#pragma mark REPRESENTATIONS

// Conversion to dictionary
- (NSDictionary *) baseDictionaryRepresentation; // no image
- (NSDictionary *) dictionaryRepresentation; // image where available
@property (nonatomic, readonly) NSDictionary *baseDictionaryRepresentation; // no image
@property (nonatomic, readonly) NSDictionary *dictionaryRepresentation; // image where available

// Conversion to data
- (NSData *) baseDataRepresentation; // no image
- (NSData *) dataRepresentation; // image where available
@property (nonatomic, readonly) NSData *baseDataRepresentation; // no image
@property (nonatomic, readonly) NSData *dataRepresentation; // image where available

+ (id) contactWithDictionary: (NSDictionary *) dict;
+ (id) contactWithData: (NSData *) data;
Expand Down
Loading