檢查從電話號碼
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;
}
}
}
感謝薩曼斯獲取圖像,但這裏的樣品是表現出一些大的內存leaksMSRCallMeBack(861,0xac5822c0)的malloc:*** MMAP(大小= 2097152)失敗(錯誤代碼= 12) ***錯誤:無法分配區域 ***在malloc_error_break中設置斷點以進行調試 MSRCallMeBack(861,0xac5822c0)malloc:*** mmap(size = 2097152)failed(error code = 12 ) ***錯誤:無法分配區域 ***在malloc_error_break中設置斷點以進行調試 MSRCallMeBack(861,0xac5822c0)malloc:*** mm ap(size = 2097152)失敗(錯誤代碼= 12) – ani
謝謝Sumanth。 – ani