人们选择了ios 7和ios 8 [英] People Picker with ios 7, and ios 8

查看:183
本文介绍了人们选择了ios 7和ios 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有人选择器在ios 7上运行,我正在尝试为ios 8添加兼容性。我已将两种方法添加到一个但是我得到一个错误,表示期望的标识符或'('在开始括号之前) NSString * contactName。任何建议都会很棒!

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


推荐答案

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

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

这篇关于人们选择了ios 7和ios 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆