-1
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);

这是我正在使用的代码,它在一个设备上工作,但无法在其他设备上获取名称,我不知道出了什么问题?它也适用于模拟器。

4

1 回答 1

0

嗨,请检查下面的链接并给出问题的答案

关联

于 2013-08-30T06:17:21.433 回答