I have two iPhone,with IOS:6.1.3 and both are 3GS , With One Phone i can access the contact with same code but in other phone its just showing me the number of contacts , but when i fetch person object like below :
person = ABAddressBookGetPersonWithRecordID(addressBook,(ABRecordID) i);
CFStringRef firstName;
firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
firstName value is NULL , I am finding person name with RecordID by looping , Please somebody can tell what is the problem.
Where as `int count = (int) ABAddressBookGetPersonCount(addressBook);`
I have the values in count .
I have given the permission and code working properly in Simulator as well as in other device , can anybody tell me what is the problem with other device.
Update:1 --
CFErrorRef myError = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &myError);
__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
accessGranted = granted;
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
//dispatch_release(sema);
}
else { // we're on iOS 5 or older
accessGranted = YES;
}
if (accessGranted) {
int count = (int) ABAddressBookGetPersonCount(addressBook);
ABRecordRef person;
for(int i = 1; i < (count + 1); i++)
{
person = ABAddressBookGetPersonWithRecordID(addressBook,(ABRecordID) i);
CFStringRef firstName;
// char *lastNameString, *firstNameString;
firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
これは私が使用しているコードです。あるデバイスでは機能しますが、他のデバイスでは名前を取得できません。何が問題なのかわかりません。また、シミュレーターでも動作します。