IOS get contact information from your system contacts

Source: Internet
Author: User

-(ibaction) Getallcontactfromsystem {
Abaddressbookref AB = abaddressbookcreatewithoptions (null, NULL);
Abaddressbookrequestaccesswithcompletion (AB, ^ (bool granted, cferrorref error) {

Get Address Book Access authorization
Abauthorizationstatus authorization= abaddressbookgetauthorizationstatus ();
if (authorization!=kabauthorizationstatusauthorized) {
NSLog (@ "has not been authorized for address Book access! ");
return;
}

Get all personnel records in the address book
Cfarrayref allpeople= abaddressbookcopyarrayofallpeople (AB);
for (int i=0; I<cfarraygetcount (allpeople); ++i) {
Abrecordref recordref = Cfarraygetvalueatindex (allpeople, i);
Get user Name
NSString *firstname = (__bridge NSString *) abrecordcopyvalue (recordref, Kabpersonfirstnameproperty);
NSString *lastname = (__bridge NSString *) abrecordcopyvalue (recordref, Kabpersonlastnameproperty);
NSString *personname = [NSString stringwithformat:@ "%@%@", Lastname,firstname];
Get phone number
Nsmutablearray *phonenumbers = [Nsmutablearray new];
Abmultivalueref phonenumbersref = Abrecordcopyvalue (RecordRef, Kabpersonphoneproperty);
for (int j=0; J<abmultivaluegetcount (phonenumbersref); ++j) {
nsstring* PhoneNumber = (__bridge NSString *) (Abmultivaluecopyvalueatindex (Phonenumbersref, J));
PhoneNumber = [PhoneNumber stringbyreplacingoccurrencesofstring:@ "-" withstring:@ ""];
if (Phonenumber.length > 0) {
[Phonenumbers Addobject:phonenumber];
}
}
}

Freeing resources
Cfrelease (allpeople);
});
}

IOS get contact information from your system contacts

Related Article

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.