I would like to use the Contacts Framework (IOS 9) to retrieve contacts that matching an email address.
Any help will be appreciated. Objective C please. Thanks.
Old question, but I stumbled on it looking to do this too. Sharing how to do this on iOS11 and above.
NSString* emailAddress = @"John-Appleseed@mac.com";
//Create repository objects contacts
CNContactStore *store = [[CNContactStore alloc] init];
NSPredicate* predicate = [CNContact predicateForContactsMatchingEmailAddress:emailAddress];
NSArray* keysToFetch = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey];
NSError *error;
NSArray *contacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keysToFetch error:&error];
if (error) {
NSLog(@"error fetching contacts %@", error);
} else {
for (CNContact *contact in contacts) {
NSLog(@"%@", contact.givenName);
}
}