我是iphone開發新手。我正在開發應用程序,我需要從通訊錄中獲取聯繫人詳細信息,如名字,電子郵件ID,電話號碼編程。並且這些值將被存儲在數組中,iam表現良好,但問題是即使爲空的聯繫人也被添加,意味着如果某人只有名字並且沒有電子郵件ID,那麼如何檢查不添加空值。這是我正在使用的代碼。如何以編程方式從通訊錄獲取聯繫人信息
ABRecordRef ref;
ABAddressBookRef m_addressbook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);
NSLog(@" n people count values %ld",nPeople);
for (int i=0; i<nPeople; i++)
{
AFContacts *contactOfAPerson = [[AFContacts alloc] init];
ref = CFArrayGetValueAtIndex(allPeople,i);
[contactOfAPerson setEmail:(NSString *)ABRecordCopyValue(ref, kABPersonEmailProperty)];
[contactOfAPerson setFirstName:(NSString *)ABRecordCopyValue(ref, kABPersonFirstNameProperty)];
//[contactOfAPerson setPhoneNumber:(NSString *)ABRecordCopyValue(ref, kABPersonPhoneMobileLabel)];
[contactList addObject:contactOfAPerson];
[contactOfAPerson release];
}
CFRelease(ref);
}