1+ /*
2+ Erica Sadun, http://ericasadun.com
3+ iPhone Developer's Cookbook, 3.0 Edition
4+ BSD License, Use at your own risk
5+ */
6+
7+ #import < UIKit/UIKit.h>
8+ #import < AddressBook/AddressBook.h>
9+ #import < AddressBookUI/AddressBookUI.h>
10+
11+
12+ #pragma mark - Human Readable Name Strings for Dictionary Conversion
13+
14+ #define FIRST_NAME_STRING @" First Name"
15+ #define MIDDLE_NAME_STRING @" Middle Name"
16+ #define LAST_NAME_STRING @" Last Name"
17+
18+ #define PREFIX_STRING @" Prefix"
19+ #define SUFFIX_STRING @" Suffix"
20+ #define NICKNAME_STRING @" Nickname"
21+
22+ #define PHONETIC_FIRST_STRING @" Phonetic First Name"
23+ #define PHONETIC_MIDDLE_STRING @" Phonetic Middle Name"
24+ #define PHONETIC_LAST_STRING @" Phonetic Last Name"
25+
26+ #define ORGANIZATION_STRING @" Organization"
27+ #define JOBTITLE_STRING @" Job Title"
28+ #define DEPARTMENT_STRING @" Department"
29+
30+ #define NOTE_STRING @" Note"
31+
32+ #define BIRTHDAY_STRING @" Birthday"
33+ #define CREATION_DATE_STRING @" Creation Date"
34+ #define MODIFICATION_DATE_STRING @" Modification Date"
35+
36+ #define KIND_STRING @" Kind"
37+
38+ #define EMAIL_STRING @" Email"
39+ #define ADDRESS_STRING @" Address"
40+ #define DATE_STRING @" Date"
41+ #define PHONE_STRING @" Phone"
42+ #define IM_STRING @" Instant Message"
43+ #define URL_STRING @" URL"
44+ #define RELATED_STRING @" Related Name"
45+ #define SOCIAL_STRING @" Social Profile"
46+
47+ #define IMAGE_STRING @" Image"
48+
49+ #pragma mark Label Quick Reference
50+
51+ /*
52+ // Generic
53+ const CFStringRef kABWorkLabel;
54+ const CFStringRef kABHomeLabel;
55+ const CFStringRef kABOtherLabel;
56+
57+ // Relation
58+ const CFStringRef kABPersonMotherLabel;
59+ const CFStringRef kABPersonFatherLabel;
60+ const CFStringRef kABPersonParentLabel;
61+ const CFStringRef kABPersonSisterLabel;
62+ const CFStringRef kABPersonBrotherLabel;
63+ const CFStringRef kABPersonChildLabel;
64+ const CFStringRef kABPersonFriendLabel;
65+ const CFStringRef kABPersonSpouseLabel;
66+ const CFStringRef kABPersonPartnerLabel;
67+ const CFStringRef kABPersonManagerLabel;
68+ const CFStringRef kABPersonAssistantLabel;
69+
70+ // URL
71+ const CFStringRef kABPersonHomePageLabel;
72+
73+ // Social
74+ const CFStringRef kABPersonSocialProfileServiceTwitter;
75+ const CFStringRef kABPersonSocialProfileServiceGameCenter;
76+ const CFStringRef kABPersonSocialProfileServiceFacebook;
77+ const CFStringRef kABPersonSocialProfileServiceMyspace;
78+ const CFStringRef kABPersonSocialProfileServiceLinkedIn;
79+ const CFStringRef kABPersonSocialProfileServiceFlickr;
80+
81+ // IM
82+ const CFStringRef kABPersonInstantMessageServiceYahoo;
83+ const CFStringRef kABPersonInstantMessageServiceJabber;
84+ const CFStringRef kABPersonInstantMessageServiceMSN;
85+ const CFStringRef kABPersonInstantMessageServiceICQ;
86+ const CFStringRef kABPersonInstantMessageServiceAIM;
87+ const CFStringRef kABPersonInstantMessageServiceFacebook;
88+ const CFStringRef kABPersonInstantMessageServiceGaduGadu;
89+ const CFStringRef kABPersonInstantMessageServiceGoogleTalk;
90+ const CFStringRef kABPersonInstantMessageServiceQQ;
91+ const CFStringRef kABPersonInstantMessageServiceSkype;
92+
93+ // Phone Numbers
94+ const CFStringRef kABPersonPhoneMobileLabel;
95+ const CFStringRef kABPersonPhoneIPhoneLabel;
96+ const CFStringRef kABPersonPhoneMainLabel;
97+ const CFStringRef kABPersonPhoneHomeFAXLabel;
98+ const CFStringRef kABPersonPhoneWorkFAXLabel;
99+ const CFStringRef kABPersonPhonePagerLabel;
100+ const CFStringRef kABPersonPhoneOtherFAXLabel;
101+
102+ // Date
103+ const CFStringRef kABPersonAnniversaryLabel;
104+ */
105+
106+ #pragma mark ABContact
107+
108+ @interface ABContact : NSObject
109+ {
110+ ABRecordRef record;
111+ }
112+
113+ // Convenience allocation methods
114+ + (id ) contact ;
115+ + (id ) contactWithRecord : (ABRecordRef) record ;
116+ + (id ) contactWithRecordID : (ABRecordID) recordID ;
117+
118+ // Class utility methods
119+ + (NSString *) localizedPropertyName : (ABPropertyID) aProperty ;
120+ + (ABPropertyType ) propertyType : (ABPropertyID) aProperty ;
121+ + (NSString *) propertyTypeString : (ABPropertyID) aProperty ;
122+ + (NSString *) propertyString : (ABPropertyID) aProperty ;
123+ + (BOOL ) propertyIsMultiValue : (ABPropertyID) aProperty ;
124+ + (NSArray *) arrayForProperty : (ABPropertyID) anID inRecord : (ABRecordRef) record ;
125+ + (id ) objectForProperty : (ABPropertyID) anID inRecord : (ABRecordRef) record ;
126+
127+ // Creating proper dictionaries
128+ + (NSDictionary *) dictionaryWithValue : (id ) value andLabel : (CFStringRef) label ;
129+ + (BOOL ) isMultivalueDictionary : (NSDictionary *) dictionary ;
130+ + (NSDictionary *) addressWithStreet : (NSString *) street withCity : (NSString *) city withState : (NSString *) state withZip : (NSString *) zip withCountry : (NSString *) country withCode : (NSString *) code ;
131+ + (NSDictionary *) imWithService : (CFStringRef) service andUser : (NSString *) userName ;
132+ + (NSDictionary *) socialWithURL : (NSString *) url withService : (NSString *) serviceName withUsername : (NSString *) username withIdentifier : (NSString *) key ;
133+
134+ // Instance utility methods
135+ - (BOOL ) removeSelfFromAddressBook : (NSError **) error ;
136+
137+ - (BOOL ) addAddress : (NSDictionary *) dictionary ;
138+ - (BOOL ) addAddressItem : (NSDictionary *)dictionary withLabel : (CFStringRef) label ;
139+ - (BOOL ) addSocial : (NSDictionary *) dictionary ;
140+ - (BOOL ) addSocialItem : (NSDictionary *) dictionary withLabel : (CFStringRef) label ;
141+ - (BOOL ) addIM : (NSDictionary *) dictionary ;
142+ - (BOOL ) addIMItem : (NSDictionary *)dictionary withLabel : (CFStringRef) label ;
143+
144+ - (BOOL ) addEmail : (NSDictionary *) dictionary ;
145+ - (BOOL ) addEmailItem : (NSString *) value withLabel : (CFStringRef) label ;
146+ - (BOOL ) addPhone : (NSDictionary *) dictionary ;
147+ - (BOOL ) addPhoneItem : (NSString *) value withLabel : (CFStringRef) label ;
148+ - (BOOL ) addURL : (NSDictionary *) dictionary ;
149+ - (BOOL ) addURLItem : (NSString *) value withLabel : (CFStringRef) label ;
150+
151+ // Sorting
152+ - (BOOL ) isEqualToString : (ABContact *) aContact ;
153+ - (NSComparisonResult ) caseInsensitiveCompare : (ABContact *) aContact ;
154+
155+ #pragma mark RECORD ACCESS
156+ @property (nonatomic , readonly ) ABRecordRef record;
157+ @property (nonatomic , readonly ) ABRecordID recordID;
158+ @property (nonatomic , readonly ) ABRecordType recordType;
159+ @property (nonatomic , readonly ) BOOL isPerson;
160+
161+ #pragma mark SINGLE VALUE STRING
162+ @property (nonatomic , assign ) NSString *firstname;
163+ @property (nonatomic , assign ) NSString *lastname;
164+ @property (nonatomic , assign ) NSString *middlename;
165+ @property (nonatomic , assign ) NSString *prefix;
166+ @property (nonatomic , assign ) NSString *suffix;
167+ @property (nonatomic , assign ) NSString *nickname;
168+ @property (nonatomic , assign ) NSString *firstnamephonetic;
169+ @property (nonatomic , assign ) NSString *lastnamephonetic;
170+ @property (nonatomic , assign ) NSString *middlenamephonetic;
171+ @property (nonatomic , assign ) NSString *organization;
172+ @property (nonatomic , assign ) NSString *jobtitle;
173+ @property (nonatomic , assign ) NSString *department;
174+ @property (nonatomic , assign ) NSString *note;
175+
176+ @property (nonatomic , readonly ) NSString *contactName; // my friendly utility
177+ @property (nonatomic , readonly ) NSString *compositeName; // via AB
178+
179+ #pragma mark NUMBER
180+ @property (nonatomic , assign ) NSNumber *kind;
181+
182+ #pragma mark DATE
183+ @property (nonatomic , assign ) NSDate *birthday;
184+ @property (nonatomic , readonly ) NSDate *creationDate;
185+ @property (nonatomic , readonly ) NSDate *modificationDate;
186+
187+ #pragma mark IMAGES
188+ @property (nonatomic , assign ) UIImage *image;
189+
190+ #pragma mark MULTIVALUE
191+ @property (nonatomic , readonly ) NSArray *emailArray;
192+ @property (nonatomic , readonly ) NSArray *emailLabels;
193+ @property (nonatomic , readonly ) NSArray *phoneArray;
194+ @property (nonatomic , readonly ) NSArray *phoneLabels;
195+ @property (nonatomic , readonly ) NSArray *relatedNameArray;
196+ @property (nonatomic , readonly ) NSArray *relatedNameLabels;
197+ @property (nonatomic , readonly ) NSArray *urlArray;
198+ @property (nonatomic , readonly ) NSArray *urlLabels;
199+ @property (nonatomic , readonly ) NSArray *dateArray;
200+ @property (nonatomic , readonly ) NSArray *dateLabels;
201+ @property (nonatomic , readonly ) NSArray *addressArray;
202+ @property (nonatomic , readonly ) NSArray *addressLabels;
203+ @property (nonatomic , readonly ) NSArray *imArray;
204+ @property (nonatomic , readonly ) NSArray *imLabels;
205+ @property (nonatomic , readonly ) NSArray *socialArray;
206+ @property (nonatomic , readonly ) NSArray *socialLabels;
207+
208+ // Each of these produces an array of strings
209+ @property (nonatomic , readonly ) NSString *emailaddresses;
210+ @property (nonatomic , readonly ) NSString *phonenumbers;
211+ @property (nonatomic , readonly ) NSString *urls;
212+
213+ // Each of these uses an array of dictionaries
214+ @property (nonatomic , assign ) NSArray *emailDictionaries;
215+ @property (nonatomic , assign ) NSArray *phoneDictionaries;
216+ @property (nonatomic , assign ) NSArray *relatedNameDictionaries;
217+ @property (nonatomic , assign ) NSArray *urlDictionaries;
218+ @property (nonatomic , assign ) NSArray *dateDictionaries;
219+ @property (nonatomic , assign ) NSArray *addressDictionaries;
220+ @property (nonatomic , assign ) NSArray *imDictionaries;
221+ @property (nonatomic , assign ) NSArray *socialDictionaries;
222+
223+ #pragma mark REPRESENTATIONS
224+ // Conversion to dictionary
225+ @property (nonatomic , readonly ) NSDictionary *baseDictionaryRepresentation; // no image
226+ @property (nonatomic , readonly ) NSDictionary *dictionaryRepresentation; // image where available
227+
228+ // Conversion to data
229+ @property (nonatomic , readonly ) NSData *baseDataRepresentation; // no image
230+ @property (nonatomic , readonly ) NSData *dataRepresentation; // image where available
231+
232+ + (id ) contactWithDictionary : (NSDictionary *) dict ;
233+ + (id ) contactWithData : (NSData *) data ;
234+ @end
0 commit comments