People Picker with ios 7, and ios 8 [duplicate]

2020-07-24 03:48发布

I have people picker working on ios 7, and I'm trying to add compatibility for ios 8. I've added both methods into one but I get an error that says expected identifier or '(' on the opening bracket before NSString *contactName. Any suggestions would be great!

- (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条回答
爷的心禁止访问
2楼-- · 2020-07-24 04:08

When a signature of delegate method is updated with new iOS version, the old one is maintained for a while. The answer is: Implement new and old methods, the right one will be called automatically.

查看更多
够拽才男人
3楼-- · 2020-07-24 04:13

For anyone who might be interested this is my working code, for both ios 7 and 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; }
查看更多
登录 后发表回答