0
我的應用程序存儲具有相同名稱的聯繫人的AddressBook recordIds,稍後嘗試將地址呈現給用戶以選擇所需的人員。但是,當我使用ABAddressBookGetPersonWithRecordID存儲的recordIds時,它返回nil。 下面的代碼表示代碼項目 - 我已經「複製」了稍後嘗試在存儲recordIds的代碼下方檢索Contact的代碼。ABAddressBookGetPersonWithRecordID返回零
NSString *full = person.compositeName;
CFArrayRef contacts = ABAddressBookCopyPeopleWithName(addressBook, (__bridge CFStringRef)(full));
CFIndex nPeople = CFArrayGetCount(contacts);
if (nPeople)
{
NSMutableArray *rIds = [[NSMutableArray alloc] init];
int numberOfContactsMatchingName = (int)CFArrayGetCount(contacts);
if (numberOfContactsMatchingName>1)
{
for (int i=0; i<numberOfContactsMatchingName; ++i)
{
ABRecordID thisId = ABRecordGetRecordID(CFArrayGetValueAtIndex(contacts, i));
NSNumber *rid = [NSNumber numberWithInteger:thisId];
FLOG(@"%d Matched, this ID = %@", numberOfContactsMatchingName, rid);
[rIds addObject:rid];
}
for (int i=0; i<rIds.count; ++i)
{
//contactRecord = ABAddressBookGetPersonWithRecordID(addressBook, (ABRecordID)recId);
ABRecordRef contactRecord;
contactRecord = ABAddressBookGetPersonWithRecordID(addressBook, rIds[i]);
if (contactRecord)
{
}
else
{
FLOG (@"Noone found with recordId %@", rIds[i]);
}
}
因此,舉例來說,我只是跑這一點,並發現具有相同名稱的地址簿中的兩個觸點 - 與IDS 143和305,但是當我再嘗試ABAddressBookGetPersonWithRecordID與IDS 143和305,都返回零。 我在這裏弄錯了什麼?
當然 - 愚蠢的我。我不知道編譯器是否可以警告它,但我想它會使用NSNumber的地址並將其視爲int。謝謝你的幫助。 – guinnessman 2014-10-03 13:08:03