Called directly after the corresponding library is included
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
-(void) Readallpeoples
{
define Address Book name AddressBook
abaddressbookref tmpaddressbook = nil;
//Depending on the system version, call different methods to get the address book
if ([[uidevice currentdevice]. Systemversion floatvalue]>=6.0) {
Tmpaddressbook = abaddressbookcreatewithoptions (null, null);
dispatch_semaphore_t sema=dispatch_semaphore_create(0);
abaddressbookrequestaccesswithcompletion (Tmpaddressbook, ^ (bool greanted, cferrorref error) {
Dispatch_semaphore_signal(SEMA);
});
Dispatch_semaphore_wait(Sema, dispatch_time_forever);
}
Else
{
Tmpaddressbook = abaddressbookcreatewithoptions (null, null);
}
//Get Address Book failed
if (tmpaddressbook==nil) {
return;
};
//The information in the Address Book is read in an array way
nsarray* tmppeoples = (__bridge nsarray*)abaddressbookcopyarrayofallpeople (tmpaddressbook);
//Traverse contacts in Contacts
For (ID tmpperson in tmppeoples) {
gets the Contact single attribute: First name
NSString* tmpfirstname = (__bridge nsstring*)abrecordcopyvalue((__bridge Abrecordref) (Tmpperson), Kabpersonfirstnameproperty);
NSLog (@ "First name:%@", tmpfirstname);
gets the Contact single attribute: Last name
NSString* tmplastname = (__bridge nsstring*)abrecordcopyvalue((__bridge abrecordref ) (Tmpperson), Kabpersonlastnameproperty);
NSLog (@ "Last name:%@", tmplastname);
gets the Contact single attribute: Nickname
NSString* tmpnickname = (__bridge nsstring*)abrecordcopyvalue((__bridge abrecordref ) (Tmpperson), Kabpersonnicknameproperty);
NSLog (@ "nickname:%@", tmpnickname);
gets the Contact single attribute: Company name
NSString* tmpcompanyname = (__bridge nsstring*)abrecordcopyvalue((__bridge Abrecordref) (Tmpperson), Kabpersonorganizationproperty);
NSLog (@ "Company name:%@", Tmpcompanyname);
gets the Contact single attribute: Job Title
NSString* tmpjobtitle= (__bridge nsstring*)abrecordcopyvalue(__bridge abrecordref ) (Tmpperson), Kabpersonjobtitleproperty);
NSLog (@ "Job title:%@", tmpjobtitle);
gets the Contact single attribute: Department name
NSString* tmpdepartmentname = (__bridge nsstring*)abrecordcopyvalue((__bridge Abrecordref) (Tmpperson), Kabpersondepartmentproperty);
NSLog (@ "Department name:%@", tmpdepartmentname);
Get Contact Single attribute: Email (s)
Abmultivalueref tmpemails = abrecordcopyvalue((__bridge abrecordref) (Tmpperson), Kabpersonemailproperty);
For (nsinteger j = 0; Abmultivaluegetcount (tmpemails); j + +)
{
nsstring* Tmpemailindex = (__bridge nsstring*)Abmultivaluecopyvalueatindex (Tmpemails, j);
NSLog (@ "emails%ld:%@", (Long) J, Tmpemailindex);
}
cfrelease (tmpemails);
gets the Contact single attribute: Birthday
NSDate* tmpbirthday = (__bridge nsdate*)abrecordcopyvalue((__bridge abrecordref ) (Tmpperson), Kabpersonbirthdayproperty);
NSLog (@ "birthday:%@", tmpbirthday);
gets the Contact single attribute: note
NSString* tmpnote = (__bridge nsstring*)abrecordcopyvalue((__bridge abrecordref ) (Tmpperson), Kabpersonnoteproperty);
NSLog (@ "note:%@", tmpnote);
gets the Contact single attribute: Generic phone number
Abmultivalueref tmpphones = abrecordcopyvalue((__bridge abrecordref) (Tmpperson), Kabpersonphoneproperty);
For (nsinteger j = 0; J < Abmultivaluegetcount (tmpphones); j + +)
{
nsstring* Tmpphoneindex = (__bridge nsstring*)Abmultivaluecopyvalueatindex (Tmpphones, j);
NSLog (@ "tmpphoneindex%ld:%@", (Long) J, Tmpphoneindex);
}
}
}
Original path: http://www.devdiv.com/ios_-blog-215400-52842.html
Get iOS Address Book information