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

北慕城南 提交于 2019-12-21 21:26:16

问题


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

回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/25902534/people-picker-with-ios-7-and-ios-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!