【问题标题】:iPhone: Create Custom Field in contactsiPhone:在联系人中创建自定义字段
【发布时间】:2010-02-13 09:51:48
【问题描述】:

我正在开发一个应用程序,我在其中将联系人添加到联系人列表。我可以获取姓名、地址、电子邮件、电话、笔记等基本信息,但我想添加一些自定义字段,如 userLabel1、userValue1、bioPersonal、bioWork、bioOther。所以我想将自定义字段添加到地址 Book'contacts。

是否可以为联系人添加自定义字段?如果是,那么请建议任何链接或示例代码?

【问题讨论】:

    标签: iphone ios field contacts


    【解决方案1】:

    基本上,没有办法做到这一点。地址簿不允许您添加自定义字段。但是,您可以将您的数据放在每个联系人的“备注”字段中。但是,这在您的其他应用程序中会显得很奇怪。

    【讨论】:

    • 嗨,我已经使用notes 字段来存储notes 信息。好的,还有一件事。是否可以隐藏后缀、昵称等字段。想法是在这些字段中存储一些值,当用户看到联系人时,这些字段不可见
    • @Rupesh:我必须在我最近做的一个应用程序中对联系人进行大量自定义。简短的回答是没有办法做到这一点。我必须编写自己的联系人视图控制器。
    【解决方案2】:
        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)
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-13
      • 1970-01-01
      • 1970-01-01
      • 2016-09-05
      相关资源
      最近更新 更多