简体   繁体   English

ABPeoplePickerNavigationController随iOS8变化?

[英]ABPeoplePickerNavigationController changes with iOS8?

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

  • 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 7.1.2:如果有人想要导入联系人,则会打开地址簿,并且您会看到完整的联系人列表,选择一个联系人后,它会打开联系人的详细信息视图,而不是您可以通过单击电话添加联系人您要导入的号码。

  • iOS 8.0: its everything similar but if you click on number of an contact it dial the phone number instead of importing it.. iOS 8.0:它的一切都很相似,但如果你点击一个联系人的号码,它拨打电话号码而不是导入它。

Code: 码:

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

couldn't find any answer in iOS developer library of apple. 在iOS的iOS开发者库中找不到任何答案。 have somebody else a solution for it? 别人有解决方案吗?

iOS 8 requires a new delegate method be implemented for this: iOS 8需要为此实现新的委托方法:

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

Keep the old delegate method in place to support iOS 7 or earlier. 保持旧的委托方法以支持iOS 7或更早版本。 What I do in my app is call the iOS 7 delegate method from the iOS 8 delegate method: 我在我的应用程序中执行的操作是从iOS 8委托方法调用iOS 7委托方法:

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

If this delegate method isn't implemented in iOS 8, tapping the value causes the action. 如果在iOS 8中未实现此委托方法,则点击该值会导致该操作。 When implemented, the delegate is called instead with the selected value. 实现时,将使用所选值调用委托。

See also the delegate method, new with iOS8: 另请参阅委托方法,iOS8的新方法:

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person;
{
    [self selectedPerson:person];
}

That's what I wanted in my case. 这就是我想要的。

This worked for me on both iOS 8 and iOS 7 and lower. 这适用于iOS 8和iOS 7及更低版本。

Note I am using this didSelectPerson:(ABRecordRef)person instead. 注意我使用的是didSelectPerson:(ABRecordRef)人。

//Needed for iOS 8
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person
{
    NSLog(@"Went here 1 ...");

    [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person];
}


//needed for iOS 7 and lower
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person 
{

    NSLog(@"Went here 2 ...");

    //add your logic here

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在iOS8上将ABPersonViewController推送到ABPeoplePickerNavigationController - Pushing ABPersonViewController to ABPeoplePickerNavigationController on iOS8 带有UITabBarController的ABPeoplePickerNavigationController在iOS8中无法正确显示 - ABPeoplePickerNavigationController with UITabBarController is not showing correctly in iOS8 iOS-iOS8中的UISearchBar宽度更改 - iOS - UISearchBar width changes in iOS8 iOS 8 ABPeoplePickerNavigationController多项选择 - iOS 8 ABPeoplePickerNavigationController Multiple Selection 在iOS 7中的ABPeoplePickerNavigationController中添加barButtonItems - Add barButtonItems in ABPeoplePickerNavigationController in ios 7 在iOS7(而非iOS8)中出现viewdidload和view之间的帧大小变化 - frame size changes between viewdidload and viewwillappear in iOS7 and not iOS8 NSLayoutConstraint layoutMargin从iOS7更改为iOS8 - NSLayoutConstraint layoutMargin changes from iOS7 to iOS8 更改视图转换会更改iOS 7上的视图位置,但不会更改ios8上的视图位置 - Changing view transform changes views positions on iOS 7 but not on ios8 在iOS 8中自定义ABPeoplePickerNavigationController的导航栏 - Customizing ABPeoplePickerNavigationController's navigationbar in iOS 8 iOS8的“位置更改”如何与“设置和警报”交互? - How do iOS8 Changes to Location interact with Settings and Alert?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM