应用和应用扩展程序从联系人簿中获取联系人

时间:2017-01-19 10:28:18

标签: objective-c swift swift3 siri sirikit

我试图整合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的应用程序联系人列表并获取它?

0 个答案:

没有答案
相关问题