Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift Firestore查询-搜索匹配联系人电话号码的字段_Swift_Firebase_Google Cloud Firestore - Fatal编程技术网

Swift Firestore查询-搜索匹配联系人电话号码的字段

Swift Firestore查询-搜索匹配联系人电话号码的字段,swift,firebase,google-cloud-firestore,Swift,Firebase,Google Cloud Firestore,我正在使用Firestore,在查询从联系人列表中提取的电话号码并将其与注册用户的电话号码进行匹配时遇到问题。我将在tableview上显示匹配的电话号码,这是我可以做的。我的问题是打电话到Firestore并从提取的联系人列表中提取匹配的电话号码。下面是代码 private func loadFriendsRecommend() { print("Attempting to fetch contacts") let store = CNContactStor

我正在使用Firestore,在查询从联系人列表中提取的电话号码并将其与注册用户的电话号码进行匹配时遇到问题。我将在tableview上显示匹配的电话号码,这是我可以做的。我的问题是打电话到Firestore并从提取的联系人列表中提取匹配的电话号码。下面是代码

private func loadFriendsRecommend() {
    print("Attempting to fetch contacts")
    let store = CNContactStore()
    store.requestAccess(for: .contacts) { (granted, error) in
        if let error = error {
            print("failed to request access", error)
            return
        }
        if granted {
            print("access granted")
            
            let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey]
            let request = CNContactFetchRequest(keysToFetch: keys as [CNKeyDescriptor])
            do {
                try store.enumerateContacts(with: request, usingBlock: { (contact, stopPointer) in
                    let contactPhoneNumbers = contact.phoneNumbers.first?.value.stringValue ?? ""
                    
                    let matchingPhoneNumbers = Firestore.firestore().collection("Person").whereField("phone", isEqualTo: contactPhoneNumbers).getDocuments() { (querySnapshot, err) in
                        if let err = err {
                            print("error getting documents: \(err)")
                        } else {
                            for document in querySnapshot!.documents {
                                print(document)
                                print("Printing the firebase query here")
                            }
                        }
                    }
                           
                })
            }
            catch let error {
                print("Failed to enumerate contact", error)
            }
        } else {
            print("access denied")
        }
    }
}
控制台输出

Attempting to fetch contacts
access granted
<FIRQueryDocumentSnapshot: 0x28290d9a0>
Printing the firebase query here
2020-09-22 21:24:49.026954-0400 Life[4862:1823038] Request <OSRequestSendLocation: 0x2804edef0> success result {
success = 1;
}
正在尝试获取联系人
允许访问
在此处打印firebase查询
2020-09-22 21:24:49.026954-0400生命[4862:1823038]请求成功结果{
成功=1;
}

查询似乎产生了一个结果。你能具体说明你的问题吗?