2014-09-30 70 views
0

我試圖在PeoplePickerNavigationController上顯示ABPersonVIewController。但它不適用於iOS 8.這是我用過的代碼。當推送到PeoplePickerNavigationController時,ABPersonViewController不檢索數據

ABPersonViewController *personVC = [[ABPersonViewController alloc] init]; 
personVC.addressBook = peoplePicker.addressBook; 
ABRecordID displayedPerson = contactId; 
personVC.displayedPerson = ABAddressBookGetPersonWithRecordID(peoplePicker.addressBook, displayedPerson); 
[peoplePicker pushViewController: personVC animated:NO]; 
[self presentViewController: peoplePicker animated:NO completion:nil]; 

可能是什麼原因,我將如何解決這個問題。

+0

我也看到這個問題 - 只在iOS 8設備上,而不在模擬器中。控制器僅顯示名稱,而不顯示其他屬性。任何人都知道解決方法? – montuno 2014-11-11 00:34:10

回答

0

這將允許您打開人員選擇器並從聯繫人中選擇信息。我不知道你需要什麼信息,但你明白了。

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { 
      [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier]; 


     NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(person)); 
     self.nameField.text = [NSString stringWithFormat:@"%@", contactName ? contactName : @"No Name"]; 


     ABMultiValueRef phoneRecord = ABRecordCopyValue(person, kABPersonPhoneProperty); 
     CFStringRef phoneNumber = ABMultiValueCopyValueAtIndex(phoneRecord, 0); 
     self.phoneField.text = (__bridge_transfer NSString *)phoneNumber; 
     CFRelease(phoneRecord); 


     ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty); 
     CFStringRef emailField = ABMultiValueCopyValueAtIndex(email, 0); 
     self.emailField.text = (__bridge_transfer NSString *)emailField; 
     CFRelease(email); 

     CFDataRef photo = ABPersonCopyImageData(person); 
     UIImage* image = [UIImage imageWithData:(__bridge NSData*)photo]; 
     if(photo) 
      CFRelease(photo); 
     if(image) 
      self.myImageView.image = image; 
     [self dismissViewControllerAnimated:YES completion:nil]; 
     return NO; 
    } 



     -(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
      shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property 
            identifier:(ABMultiValueIdentifier)identifier 
     { 
      [self dismissViewControllerAnimated:YES completion:nil]; 
      return NO; } 
相關問題