[英]ABMultiValueIdentifier is always 0 (Zero) ABPeoplePicker
我試圖讓用戶可以從他們的聯系人中選擇一個電話號碼,然后在UITextField中顯示所選的號碼。
問題是,無論您在聯系人上選擇哪個號碼,從shouldContinueAfterSelectingPerson
返回的ABMultiValueIdentifier
始終為0。
這是我的代碼:
- (IBAction)btnChooseContactClicked:(id)sender {
[[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[picker setDisplayedProperties: [NSArray arrayWithObjects: [NSNumber numberWithInt: kABPersonPhoneProperty], nil]];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
}
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
return YES;
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier //Always = 0
{
[self displayPerson:person property:property identifier:identifier];
[self dismissModalViewControllerAnimated:YES];
return NO;
}
- (void)displayPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSLog(name);
if (property == kABPersonPhoneProperty) {
ABMultiValueRef multiPhones = ABRecordCopyValue(person, kABPersonPhoneProperty);
for(CFIndex i = 0; i < ABMultiValueGetCount(multiPhones); i++) {
if(identifier == ABMultiValueGetIdentifierAtIndex (multiPhones, i)) {
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(multiPhones, i);
CFRelease(multiPhones);
NSString *phoneNumber = (__bridge NSString *) phoneNumberRef;
CFRelease(phoneNumberRef);
self.txtTelNo.text = phoneNumber;
}
}
}
}
感覺我做的一切都不錯,並且跟隨了無數其他人,而且似乎沒有任何效果。 可能是什么問題?
在iOS8中,無需先進行身份驗證即可使用ABPeoplePickerViewController。 如果這樣做,則只允許訪問用戶選擇的值的數據-所有其他ID均設置為無效。
在打開ABPeoplePickerViewController之前,請先嘗試進行身份驗證,然后檢查是否接收到正確的數據。
嘗試檢索被選人的縮略圖時,我遇到了同樣的問題-如果不進行身份驗證,則始終為空。
事實證明,問題出在我手機中的測試用戶。 該用戶有2個電話號碼,兩個電話號碼均設置為“移動”類型。 如果是這種情況,選擇器似乎看不到它們之間的差異。 任何人都可以確認這一點,或者我是在這里說話呢?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.