如何通过传递手机号码作为参数来从地址簿中获取人员的联系人图像。我不想打开通讯录。
我有一个图像井和其他一个带有数字的文本字段和一个用于获取图像的按钮。
我只想将 10 位数字放入文本字段。然后按按钮,然后我想从地址簿中获取具有该号码的人的缩略图。 我只想从我从 UIView 传递的手机号码中获取人员的缩略图。但我不想打开地址簿并从列表中选择任何联系人到我的 UIView 页面。
请任何人帮我获取代码。我是 iPhone 开发新手。
最佳答案
检查从电话号码获取图像的示例
NSString phoneNumber = @"yourPhoneNumber";
UIImage *myContactImage;
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);
// 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: @""];
phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:toExclude] componentsJoinedByString: @""];
if ([phone isEqualToString:phoneNumber]) {
NSData *contactImageData = (NSData*)ABPersonCopyImageData(person);
myContactImage = [[UIImage alloc] initWithData:contactImageData];
break;
break;
}
}
}
关于iphone - 如何通过传递手机号码作为参数从地址簿中获取人员的联系人图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14070265/