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

This is the code which I am using , It does work in one device , but cannot fetch the name in other device , I dont know whats wrong ? And it works in simulator as well.

有帮助吗?

解决方案

Hi please check the under link and give that questions answer

link

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top