gpt4 book ai didi

ios - 更新现有的 'Contacts' 电话号码?

转载 作者:行者123 更新时间:2023-11-28 15:22:33 25 4
gpt4 key购买 nike

我有代码从联系人中获取和显示用户数据(各种名称属性加上电话号码数组)。通过创建 CNMutableContact,我可以更新任何 Name 属性。但我只能显示电话号码(来自 CNLabeledValue 通过“.digits”)。是否也可以更新电话号码?我无法更改 CNMutableContact 中的“数字”,因为它是“只读的”。我已经看到并理解有关访问 CNLabeledValue“数字”的注意事项,但仍想继续。

建议?

最佳答案

也许回答这个问题有点晚了。但是,在给定的示例中,您只能添加电话号码。因此,要更新电话,您充其量只是删除电话号码并添加新电话号码。

在此方法中替换电话号码条目将导致更改电话号码标识符

这应该不是您期望的行为,因为您正在更改现有条目的电话号码。我们希望电话标识符保持完整。

您应该使用 CNLabeledValue 中的 settingValue 请参阅: Apple Documentation

// Clone to a mutable contact
let mutableContact = contact.mutableCopy() as! CNMutableContact

// Here's the catch
let updatedPhone = mutableContact.phoneNumbers[0].settingValue(CNPhoneNumber(stringValue: "newPhone"))

// Be aware that in this example, I only have on phone number. For multiple phones, would need to handle multiple phones properly in the array.
mutableContact.phoneNumbers = [updatedPhone]

关于ios - 更新现有的 'Contacts' 电话号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45742009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com