【问题标题】:People Picker with ios 7, and ios 8 [duplicate]带有ios 7和ios 8的人员选择器[重复]
【发布时间】:2014-09-18 00:51:10
【问题描述】:

我有人员选择器在 ios 7 上工作,我正在尝试添加对 ios 8 的兼容性。我已将这两种方法添加到一个中,但我收到一个错误,上面写着预期的标识符或 '(' 之前的左括号NSString *contactName。任何建议都会很棒!

- (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; }

【问题讨论】:

  • 我要做的就是实现旧的委托方法和新的委托方法。将自动调用正确的。
  • 谢谢!我认为这是一种更好的方法
  • 我已经更新了我的代码 sn-p,它抛出了一个错误关于如何解决这个问题的任何想法?
  • 在 peoplePickerNavigationController:didSelectPerson: 方法之后有一个不匹配的 "} {"

标签: ios objective-c ios7 ios8 abpeoplepickerview


【解决方案1】:

对于任何可能感兴趣的人,这是我的工作代码,适用于 ios 7 和 ios 8

- (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; }

【讨论】:

  • 谢谢!!这对我有用:)
【解决方案2】:

当代理方法的签名随着新的 iOS 版本更新时,旧的会保留一段时间。 答案是: 实现新旧方法,会自动调用正确的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 2014-11-19
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多