2015-08-29 65 views
0

在myapp我從聯繫人中選擇電話號碼。 我需要存儲記錄ID,然後檢索recordref。 爲了測試邏輯,我試了下面的示例 在下面的委託中,我記錄了該人員的記錄ID。 然後嘗試檢索Recordref。 錄音機(gref)爲空 請讓我知道我做錯了什麼。 我一直在使用,我們需要得到授權訪問地址簿中的許可地址簿之前OS 8.2ABAddressBookGetPersonWithRecordID返回NULL

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person 
{ 

    ABRecordID sid = ABRecordGetRecordID(person); 

    ABAddressBookRef addressBook = ABAddressBookCreate(); 

    ABRecordRef gref = ABAddressBookGetPersonWithRecordID(addressBook, sid); 

    NSLog(@「org record ref %@",person); 

    NSLog(@「new record ref %@",gref); 

} 

回答

0

測試了這個在iPhone 6。 示例

CFErrorRef myError = NULL; 
ABAddressBookRef myAddressBook = ABAddressBookCreateWithOptions(NULL, &myError); 

__block ABRecordRef gref; 

ABAddressBookRequestAccessWithCompletion(myAddressBook, 
             ^(bool granted, CFErrorRef error) { 
        if (granted) { 

         gref = ABAddressBookGetPersonWithRecordID(myAddressBook, sid); 
         NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(gref)); 

         NSLog(@"after record ref %@",gref); 
         NSLog(@"human name %@",contactName); 

        } else { 

         // Handle the case of being denied access and/or the error. 

        } 

              CFRelease(myAddressBook); 

      });