like title what is the best and efficient way to find a contact in device addressbook by phone number? Actually i use a method like this:
Note that:
[rm getElencoContatti]
returns all contacts in addressbook
[contatto getID]
returns contacts id from addressbook
[contatto getNumeriContatto]
returns all contacts' phone number from addressbook
+(NSMutableDictionary *)getNomeContattoDaNumero:(NSString *)numeroTelefono {
NSMutableDictionary *returnValue = [[NSMutableDictionary alloc]init];
NSNumber *idContact;
for(ContattoRubrica *contatto in [rm getElencoContatti]) {
idContact = [contatto getID];
for(id numero in [contatto getNumeriContatto]) {
if([numeroTelefono isEqualToString:[numero objectForKey:@"numeroTelefono"]]) {
[returnValue setValue:[contatto getNomeContatto] forKey:@"nome"];
[returnValue setValue:idContact forKey:@"idContatto"];
return returnValue;
}
}
}
[returnValue setValue:numeroTelefono forKey:@"nome"];
[returnValue setValue:[NSNumber numberWithInt:-1] forKey:@"idContatto"];
return returnValue;
}
I tested this method with addressbook of about 200 contact, and this function is very slowly. Exist any ABAddressbook.h method that do this automatically ?
Thanks in advance.