2012-12-28 79 views
2

如何通過將手機號碼作爲參數獲取通訊錄中人員的聯繫人圖片。我不想打開地址簿。如何通過將手機號碼作爲參數獲取通訊錄中的人的聯繫人圖片

我有一個圖像和其他一個文本字段與數字和一個按鈕來獲取圖像。

我只想把10位數字放到文本字段中。然後按下按鈕,然後我想從地址簿中獲取具有此號碼的人員的縮略圖圖像。 我只想從手機號碼中獲取人物的縮略圖圖像,但是我不想打開地址簿並從列表中選擇任何聯繫人到我的UIView頁面。

請任何人幫我代碼。我是iphone開發新手。

回答

2

檢查從電話號碼

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; 
      } 
     } 
    } 
+0

感謝薩曼斯獲取圖像,但這裏的樣品是表現出一些大的內存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

+0

謝謝Sumanth。 – ani

相關問題