ABPeoplePickerNavigationController随iOS8变化? [英] ABPeoplePickerNavigationController changes with iOS8?

查看:122
本文介绍了ABPeoplePickerNavigationController随iOS8变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我已经将iPhone上的XCode(6.0,6A313)和我的iOS(8.0,12A365)更新为gm种子,因此ABPeoplePickerNavigationController代码不像以前那样工作。

Since I have updated XCode (6.0, 6A313) and my iOS (8.0, 12A365) on the iPhone to gm seeds, the ABPeoplePickerNavigationController code doesn't work like before.


  • iOS 7.1.2:如果有人想要导入联系人,地址簿会打开,您会看到完整的联系人列表,在选择一个联系人后,会打开联系人的详细信息视图而且只需点击要导入的电话号码即可添加联系人。

  • iOS 7.1.2: If someone want to import a contact, the address book opens and you see the full list of contacts, after picking one, it opens detail view of an contact and than you can add the contact with a click of the phone number you want to import.

iOS 8.0:它的一切都很相似但是如果你点击一个联系人的号码就拨打电话号码而不是导入它..

iOS 8.0: its everything similar but if you click on number of an contact it dial the phone number instead of importing it..

代码:

#pragma mark - AddressBook Delegate Methods

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
    return YES;
}


-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{

    // Get the first and the last name. Actually, copy their values using the person object and the appropriate
    // properties into two string variables equivalently.
    // Watch out the ABRecordCopyValue method below. Also, notice that we cast to NSString *.
    NSString *firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    NSString *lastName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);

    // Compose the full name.
    NSString *fullName = @"";
    // Before adding the first and the last name in the fullName string make sure that these values are filled in.
    if (firstName != nil) {
        fullName = [fullName stringByAppendingString:firstName];
    }
    if (lastName != nil) {
        fullName = [fullName stringByAppendingString:@" "];
        fullName = [fullName stringByAppendingString:lastName];
    }


    // Get the multivalue number property.
    CFTypeRef multivalue = ABRecordCopyValue(person, property);

    // Get the index of the selected number. Remember that the number multi-value property is being returned as an array.
    CFIndex index = ABMultiValueGetIndexForIdentifier(multivalue, identifier);

    // Copy the number value into a string.
    NSString *number = (__bridge NSString *)ABMultiValueCopyValueAtIndex(multivalue, index);

    nameTextField.text = fullName;
    numberTextField.text = number;

    // Dismiss the contacts view controller.
    [_addressBookController dismissViewControllerAnimated:YES completion:nil];

    return NO;
}


// Implement this delegate method to make the Cancel button of the Address Book working.
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
    [_addressBookController dismissViewControllerAnimated:YES completion:nil];
}

在iOS的iOS开发者库中找不到任何答案。
还有其他人的解决方案吗?

couldn't find any answer in iOS developer library of apple. have somebody else a solution for it?

推荐答案

iOS 8需要为此实现新的委托方法:

iOS 8 requires a new delegate method be implemented for this:

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
}

保持旧的委托方法以支持iOS 7或更早版本。我在我的应用程序中执行的操作是从iOS 8委托方法调用iOS 7委托方法:

Keep the old delegate method in place to support iOS 7 or earlier. What I do in my app is call the iOS 7 delegate method from the iOS 8 delegate method:

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
    [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier];
}

如果在iOS 8中未实现此委托方法,则点击值会导致那个行动。实现时,将使用所选值调用委托。

If this delegate method isn't implemented in iOS 8, tapping the value causes the action. When implemented, the delegate is called instead with the selected value.

这篇关于ABPeoplePickerNavigationController随iOS8变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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