J'essaye d'être un ABRecordRef qui représente les informations de contact d'une personne du carnet d'adresses. J'ai construit deux fonctions qui appelle une fonction pour remplir une structure de données personnelles avec l'information dans ABRecordRef.kABPersonAddressProperty provoque des plantages sous ABAddressBookGetPersonWithRecordID
vient ici les déclarations de fonction pour les trois fonctions:
+ (NSMutableArray*) getAllContactProfiles{
NSMutableArray *listOfProfile = [[NSMutableArray alloc] init];
//---get the contact information for the api
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex numberOfPeopleInAddressBook = ABAddressBookGetPersonCount(addressBook);
//<- Here I loop through all the contacts and pass the ABRecordRef into the following function
//---release the variables---
CFRelease(addressBook);
CFRelease(people);
[listOfProfile autorelease];
return listOfProfile;
}
La fonction suivante
+ (MSProfileEntry*) getPersonProfileThroughABRecordRef:(ABRecordRef) person{
MSProfileEntry *mockProfile;
ABRecordID recID=ABRecordGetRecordID(person);
//get the user name
CFStringRef firstName;
firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);//it goes wrong here!
CFStringRef lastName;
lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
//bla bla bla.. the rest of the code
}
Tout va très bien. Cependant, lorsque je tente d'obtenir les ABRecordRef par ABAddressBookGetPersonWithRecordID comme il est dans la méthode suivante:
La méthode suivante
+ (MSProfileEntry*) getPersonProfileThroughContactId:(NSInteger*)contactId{
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person =
ABAddressBookGetPersonWithRecordID(addressBook, (ABRecordID)contactId);
CFRelease(addressBook);
if (person == nil) {
return nil;
}
return [MSContactUtil getPersonProfileThroughABRecordRef:person];
}
L'ensemble application se bloque en ligne: ABRecordCopyValue(person, kABPersonFirstNameProperty);
.
Le problème est maintenant que ABRecordCopyValue(person, kABPersonFirstNameProperty);
fonctionne parfaitement bien avec ABAddressBookCopyArrayOfAllPeople
mais provoque l'application de planter avec ABAddressBookGetPersonWithRecordID
.
Quelqu'un sait-il comment résoudre ce problème? Je ne veux vraiment pas boucler toute la base de contact juste pour chercher un contact.
Merci! Je vais essayer! –
J'ai modifié ma réponse. Voir la méthode 'getPersonProfileThroughContactId' comme il se doit ... –