我是 iphone 开发的新手。我正在开发应用程序,如果我需要以编程方式从通讯录中获取联系方式,例如名字、电子邮件 ID、电话号码。这些值要存储在数组中,我做得很好,但问题是即使添加了空联系人也意味着如果有人只有姓名而没有电子邮件 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);
}