How can I get the contact details from iPad and use it in my app. I am using the following code and getting the details from simulator. But while running in ipad i am not getting the contact image, email etc. i am getting the phone number correctly.
ABAddressBookRef addressBook = ABAddressBookCreate();
// Get all contacts in the addressbook
NSArray *allPeople = (__bridge NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
for (id person in allPeople) {
// Get all phone numbers of a contact
ABMultiValueRef phoneNumbers = ABRecordCopyValue((__bridge ABRecordRef)(person), kABPersonPhoneProperty);
ABMultiValueRef emailaddress = ABRecordCopyValue((__bridge ABRecordRef)(person), kABPersonEmailProperty);
// If the contact has multiple phone numbers, iterate on each of them
for (int i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
NSString *phone = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, i);
// Remove all formatting symbols that might be in both phone number being compared
NSCharacterSet *toExclude = [NSCharacterSet characterSetWithCharactersInString:@"/.()- +"];
phone = [[phone componentsSeparatedByCharactersInSet:toExclude] componentsJoinedByString: @""];
if ([phone isEqualToString:number]) {
NSData *contactImageData = (__bridge NSData*)ABPersonCopyImageData((__bridge ABRecordRef)(person));
NSString *mail = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(emailaddress, i);
NSLog(@"%@",mail);
if(mail)
{
hasEmail=TRUE;
NSLog(@"true");
}
else{
hasEmail=FALSE;
NSLog(@"false");
}
ContactImage = [[UIImage alloc] initWithData:contactImageData];
// [conImage setImage:ContactImage];
break;
break;
}
}
}
if(ContactImage)
{
[conImage setImage:ContactImage];
}
else{
NSLog(@"no image");
}
I need to get the image while running on ipad