NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);
BOOL isExisted=FALSE;
for (id record in allContacts){
ABRecordRef thisContact = (__bridge ABRecordRef)record;
if(thisContact!=nil){
if (CFStringCompare(ABRecordCopyCompositeName(thisContact),
ABRecordCopyCompositeName(newPerson), 0) == kCFCompareEqualTo){
//The contact already exists!
isExisted=YES;
}
}
}
上面是我的代码,用于获取联系人并检查该联系人是否已存在于地址簿中,但如果
,则会收到错误。(CFStringCompare(ABRecordCopyCompositeName(thisContact),
ABRecordCopyCompositeName(newPerson), 0) == kCFCompareEqualTo)
任何人都可以帮助我..
正在使用ARC Enabled Project
答案 0 :(得分:0)
您好我遇到了同样的问题,问题是检查您当前的新人是否没有任何字段,并在进行比较之前检查此联系人名称字段是否为零。
这就是我的表现:
NSString *firstName = CFBridgingRelease(ABRecordCopyValue(thisContact, kABPersonFirstNameProperty));
NSString *lastName = CFBridgingRelease(ABRecordCopyValue(thisContact, kABPersonLastNameProperty));
您可以查看电话号码,如果您想进行比较,请发送电子邮件