0

我正在尝试集成 Siri。为此,我为我的应用打开了 AppGrouping。我试图使用用户默认值来保存联系人。但它说:“尝试设置一个非属性列表对象”。我做错了什么?

class func allContacts() {
        let store = CNContactStore();

        let request = CNContactFetchRequest(keysToFetch: [CNContactGivenNameKey as CNKeyDescriptor,CNContactPhoneNumbersKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor,CNContactImageDataKey as CNKeyDescriptor,CNContactThumbnailImageDataKey as CNKeyDescriptor,CNContactNicknameKey as CNKeyDescriptor])
        var localContacts = [INContact]()

        do{
            try store.enumerateContacts(with: request, usingBlock: { (contact, status) -> Void in
                let newContact = INContact(name: contact.givenName, phone: contact.phoneNumbers)
                localContacts.append(newContact)
            })
        }
        catch let error as NSError! {
            print ("Error: \(error.domain)")
        }
        guard let shared = UserDefaults.init(suiteName: "group.mygroup.com") else {
            return
        }
        shared.setValue(localContacts, forKey: "Contacts")
        shared.synchronize()
    }

如何获取 IntentHandler 的应用程序联系人列表并获取它?

4

0 回答 0