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

這是我正在使用的代碼,它在一個設備上工作,但無法在其他設備中獲取該名稱,我不知道最新錯誤?它也可以在模擬器中使用。從Iphone地址簿中獲取聯繫人

+0

顯示此「的recordId循環」!你爲什麼(需要)施放我? –

+0

@意義 - 事情我認爲krish是一個循環計數的'ABAddressBookGetPersonCount'和我是int增量變量。 –

+0

@意義事項和Nitin,對不起,請延期,請看代碼 – krish

回答

0

你好請檢查下面的鏈接,並給予該問題回答

link

+0

請檢查代碼,我已更新。 – krish

相關問題