【发布时间】:2010-02-13 09:51:48
【问题描述】:
我正在开发一个应用程序,我在其中将联系人添加到联系人列表。我可以获取姓名、地址、电子邮件、电话、笔记等基本信息,但我想添加一些自定义字段,如 userLabel1、userValue1、bioPersonal、bioWork、bioOther。所以我想将自定义字段添加到地址 Book'contacts。
是否可以为联系人添加自定义字段?如果是,那么请建议任何链接或示例代码?
【问题讨论】:
我正在开发一个应用程序,我在其中将联系人添加到联系人列表。我可以获取姓名、地址、电子邮件、电话、笔记等基本信息,但我想添加一些自定义字段,如 userLabel1、userValue1、bioPersonal、bioWork、bioOther。所以我想将自定义字段添加到地址 Book'contacts。
是否可以为联系人添加自定义字段?如果是,那么请建议任何链接或示例代码?
【问题讨论】:
基本上,没有办法做到这一点。地址簿不允许您添加自定义字段。但是,您可以将您的数据放在每个联系人的“备注”字段中。但是,这在您的其他应用程序中会显得很奇怪。
【讨论】:
let store = CNContactStore()
// phoneNumberToEdit is the CNContact which you need to update
guard var mutableCont = phoneNumberToEdit?.mutableCopy() as? CNMutableContact else { return }
let phoneNumber = CNPhoneNumber(stringValue: "0123456789")
var currentContact = CNLabeledValue(label: "MyCustomLabel", value: phoneNumber)
mutableCont.phoneNumbers = [currentContact]
let request2 = CNSaveRequest()
request2.update(mutableCont)
do{
try store.execute(request2)
} catch let error{
print(error)
}
【讨论】: