[英]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.