2013-08-30 6 views
-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); 

이것은 하나의 장치에서 작동하지만 다른 장치에서 이름을 가져올 수없는 코드입니다. 무엇이 잘못 되었나요? 그리고 그것은 시뮬레이터에서도 잘 작동합니다.아이폰의 주소록을 가져 오는 중

+0

쇼에 답 것을 적어주세요! 너 왜 캐스팅해야 해? –

+0

@ 의미 - 문제 내가 생각하기에 크리쉬는 'ABAddressBookGetPersonCount'의 카운트가 반복되고 i가 증가분에 대해 int 변수가된다고 생각합니다. –

+0

@ 의논과 Nitin, 죄송합니다 코드를 보시길 바랍니다 – krish

답변

0

는 안녕 아래 링크를 확인하고 질문이 'recordId를 루프'

link

+0

코드를 확인하십시오, 업데이트했습니다. – krish

관련 문제