ios - 无法将号码添加到 ios 11 中的现有联系人

标签 ios objective-c contacts addressbook abaddressbook

我想将电话号码添加到现有联系人中。此代码在 iOS8 中完美运行,但不适用于 iOS11。没有收到任何错误,但是当 ABNewPersonViewController 打开时我看不到新的电话号码。

-(void)addToExstingContact{

    ABPeoplePickerNavigationController *personPicker = [[ABPeoplePickerNavigationController alloc] init];
    personPicker.peoplePickerDelegate = self;

    [self presentViewController:personPicker animated:true completion:nil];
}

-(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person{

    [peoplePicker dismissViewControllerAnimated:true completion:^{

        ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
        ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutableCopy(phoneNumbers);
        ABMultiValueAddValueAndLabel(phoneNumberMultiValue, (__bridge CFTypeRef)(newPhoneNumber), kABPersonPhoneMainLabel, NULL);

        ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil);
        CFRelease(phoneNumberMultiValue);

        ABNewPersonViewController *view = [[ABNewPersonViewController alloc] init];
        view.newPersonViewDelegate = self;
        view.displayedPerson = person;

        UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:view];
        [self presentViewController:newNavigationController animated:true completion:nil];
    }];
}

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
    [peoplePicker dismissViewControllerAnimated:true completion:nil];
}

最佳答案

引用文档:

The Address Book UI framework is deprecated in iOS 9. Use the APIs defined in the ContactsUI framework instead. To learn more, see ContactsUI.

也许您应该将此代码重写到联系人框架中以使其在 11 上运行?

这里有一个例子: https://www.appsfoundation.com/post/create-edit-contacts-with-ios-9-contacts-ui-framework

关于ios - 无法将号码添加到 ios 11 中的现有联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49231102/

相关文章:

ios - 如何将事件标题(从 UI TextView )添加到我的应用程序创建的日历事件中?

android - 'soft launch' 使用 Expo 构建的新 React Native 应用程序的最佳方法是什么?

ios - 使用分页向 UIScrollView 水平添加图像

ios - CvVideoCamera - 相机不可用,Iphone 模拟器

ios - iOS9联系人框架缺少电话号码标签?

ios - 将 ABPeoplePicker 限制为一组,而不是所有联系人

ios - 如何在 swift 4 和 xcode 9 中单击 UITableViewCell 中的按钮更新 UILabel?

iphone - Objective-c 调用 C 函数

ios - 在 iOS 二进制文件 (ipa) 中插入或添加新的库加载命令

php - 联系表单问题 - 我确实收到消息,但没有内容(空白页)