Ios 如何避免通讯簿中的重复联系人?
您好,我正在从通讯簿中检索联系人,但我也获得了副本,例如:Ios 如何避免通讯簿中的重复联系人?,ios,iphone,objective-c,addressbook,Ios,Iphone,Objective C,Addressbook,您好,我正在从通讯簿中检索联系人,但我也获得了副本,例如: 萨姆-1234567890 萨姆-1234567890 都存在于通讯录中,这两者都可以得到,是否有任何属性可以避免这种情况。但如果同一名称的编号不同,则该方法有效。 我的代码: -(无效)获取联系人地址簿:(ABRecordRef)个人 { NSMutableArray*arrayContactsFromAddressbook; AppDelegate*委托=(AppDelegate*)[[UIApplication sharedApp
-(无效)获取联系人地址簿:(ABRecordRef)个人
{
NSMutableArray*arrayContactsFromAddressbook;
AppDelegate*委托=(AppDelegate*)[[UIApplication sharedApplication]委托];
NSMutableDictionary*dictContacts=[[NSMutableDictionary alloc]init];
ABRecordID=ABRecordGetRecordID(个人);
[NSNumber Number Withint:recordId]forKey:@“recordId”];
NSString*firstName=(uu桥NSString*)(ABRecordCopyValue(person,kabbersonfirstnameproperty));
NSString*lastName=(uu桥NSString*)(ABRecordCopyValue(person,kABPersonLastNameProperty));
if(firstName!=nil)
[setObject:firstName forKey:@“firstName”];
如果(lastName!=nil)
[setObject:lastName forKey:@“lastName”];
其他的
[setObject:@“forKey:@“lastName”];
ABMultiValueRef phoneNumbers=ABRecordCopyValue(person,kABPersonPhoneProperty);
NSString*strPhoneNumber;
NSMutableDictionary*DictPhoneNumber=[[NSMutableDictionary alloc]init];
对于(CFIndex i=0;i=10)
{
NSString*trimmedString=[strippedNumber substringFromIndex:[strippedNumber长度]-10];
[DictPhoneNumber设置对象:trimmedString forKey:phoneLabel];
}
//CFRelease(locLabel);
}
[dictContacts setObject:dictPhoneNumbers-forKey:@“phoneNumbers”];
如果([[dictContacts objectForKey:@“PhoneNumber”]计数])
{
[ArrayContactsFromAddressBookAddObject:dictContacts];
}
}
arrayContactsFromAddressbook
包含通讯簿中的所有联系人。如何根据电话号码删除重复项 用电话号码作为你创建的临时字典的键。我不明白你的意思。比如我用钥匙该怎么办?
-(void)getContactsFromAddressBook:(ABRecordRef)person
{
NSMutableArray *arrayContactsFromAddressbook;
AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
NSMutableDictionary *dictContacts=[[NSMutableDictionary alloc] init];
ABRecordID recordId = ABRecordGetRecordID(person);
[dictContacts setObject:[NSNumber numberWithInt:recordId] forKey:@"recordId"];
NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
if(firstName!=nil)
[dictContacts setObject:firstName forKey:@"firstName"];
if(lastName!=nil)
[dictContacts setObject:lastName forKey:@"lastName"];
else
[dictContacts setObject:@"" forKey:@"lastName"];
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *strPhoneNumber;
NSMutableDictionary *dictPhoneNumbers = [[NSMutableDictionary alloc] init];
for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++)
{
strPhoneNumber = (__bridge NSString *) ABMultiValueCopyValueAtIndex(phoneNumbers, i);
CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(phoneNumbers, i);
NSString *phoneLabel = (__bridge NSString*) ABAddressBookCopyLocalizedLabel(locLabel);
NSString * strippedNumber = [strPhoneNumber stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [strPhoneNumber length])];
if ([strippedNumber length]>=10)
{
NSString *trimmedString = [strippedNumber substringFromIndex:[strippedNumber length]-10];
[dictPhoneNumbers setObject:trimmedString forKey:phoneLabel];
}
// CFRelease(locLabel);
}
[dictContacts setObject:dictPhoneNumbers forKey:@"phoneNumbers"];
if ([[dictContacts objectForKey:@"phoneNumbers"] count])
{
[arrayContactsFromAddressbook addObject:dictContacts];
}
}