objective-c - CNContact :migration from ABAddressBook : iOSLegacyIdentifier + lastModifcationDate

标签 objective-c swift contacts ios9 abaddressbook

我有一个存储所有本地用户联系人的数据库。 现在我想使用新的框架(联系框架),我的问题是 CNContact 现在有一个新的标识符(不再是自动增量的)称为“标识符”,我不能在我的数据库中使用联系人的潜在更新。

我有两个问题:

  1. 在 xcode 调试器中,我可以看到 _iOSLegacyIdentifier(旧的、自动增量的)作为 CNContact 中的一个属性,我如何在没有私有(private) API 调用的情况下获取它
  2. 我看不到 CNContact 的“lastModifcationDate”(在 ABAddressBook 框架中它称为 kABPersonModificationDateProperty)我如何使用新框架获取它。

谢谢。

[编辑]:我已经就此向 Apple 开票,答案如下:

There are no plans to address this based on the following:

1) iOSLegacyIdentifier is private API for CNContact. 2) A modification date is not offered on CNContact.

To migrate your DB you can to match contacts by name and disambiguate by manually matching other properties like email addresses or phone numbers.

We are now closing this report.

如您所见,没有真正的解决方案,我们必须猜测..

最佳答案

您可以使用新的 Contact Framework 获取 ContactID (iOSLegacyIdentifier)。我在我的应用程序中使用它来查找特定联系人的 iOSLegacyIdentifier,您可以随意修改。

let predicate = CNContact.predicateForContacts(matchingName: "contactName")
        let toFetch = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactIdentifierKey]

        do{
            let contacts = try self.contactStore.unifiedContacts(matching: predicate, keysToFetch: toFetch as [CNKeyDescriptor])

            for contact in contacts{
                var diccionario:[String : Any] = contact.dictionaryWithValues(forKeys: ["iOSLegacyIdentifier"])
                //With this you can see/obtain iOSLegacyIdentifier
                print(diccionario["iOSLegacyIdentifier"] as! Int)
                return;
            }
        } catch let err{
            print(err)
        }

关于objective-c - CNContact :migration from ABAddressBook : iOSLegacyIdentifier + lastModifcationDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32721698/

相关文章:

iphone - 在第四行末尾追加 "..."

ios - 当我更改 iPhone 的语言时,会导致崩溃吗?

swift - iOS Swift 3 - 删除周年纪念日联系信息字段

iphone - 应用程序发布后,对如何更新 UITableView 上的数据源感到困惑

ios - 计算日期之间的周数,并将其呈现为 NSString(如 Instagram)

ios - 从 .m 文件生成方法声明

swift 和RAII : deinit behavior inconsistent between project and playground

swift - 快速解析文本中的单位和金额

android - 未经许可读取联系人?

android:如何选择联系人电话号码