I'm trying to get the duplicate phone numbers on iPhone address book . my problem that it's really taking time i have like 264 contact on my iPhone and the process taking like 16 sec !!! i have purchased app from iTunes doing same process taking like no time . so i believe that my approach is incorrect . i know that in Xcode i should use NSPredicate . i tried to do that with c# predicate but same result . below is my code to get duplicate phone numbers :
ABAddressBook ab = new ABAddressBook ();
OrderedDictionary persons = new OrderedDictionary ();
foreach (ABPerson p in ab.GetPeople()) {
foreach (var phoneNumber in p.GetPhones().GetValues()) {
var duplicates = SearchByPhoneNumber (ab, phoneNumber);
if (duplicates.Count > 1) {
if (!persons.Contains (phoneNumber)) {
persons.Add (phoneNumber, duplicates);
}
}
}
}
private List<ABPerson> SearchByPhoneNumber ( ABAddressBook ab, string phoneNumber)
{
List<ABPerson> duplicatepeople = new List<ABPerson> ();
phoneNumber = Regex.Replace (phoneNumber, "[^0-9]", "");
var people = ab.Where(x=> x is ABPerson).Cast<ABPerson>()
.Where((e)=> { return (e.GetPhones().Any((p)=>{return (Regex.Replace(p.Value,"[^0-9]", "")==phoneNumber); }));}).ToList ();
return people;
}