-(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