如何从 iPad 获取联系方式并在我的应用程序中使用它。我正在使用以下代码并从模拟器中获取详细信息。但是在 ipad 中运行时,我没有得到联系人图像、电子邮件等。我得到了正确的电话号码。
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");
}
我需要在 ipad 上运行时获取图像