Get iOS Address Book information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.