0

I'm trying to implement firebase database with swifts AwaitKit, which delivers await/async and uses swifts PromiseKit under hood. The problem is that when I put firebase code inside promise it always fails on NSURLSession with this error

"NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)"

However http call it self uses https not http. I tried to allow NSAllowsArbitraryLoads, NSExceptionDomains nothings helps me. Here is code.

let data: [String: Any] = [
        "test": 1,
        "test2": "user"
    ]

    let promise: Promise<Bool> = Promise { resolve, reject in
        ref.child("test/picks").setValue(data) { err, _ in
            if err == nil {
                resolve(true)
            } else {
                reject(err!)
            }
        }
    }

    let isStored = try! await(promise)
Jack
  • 13,571
  • 6
  • 76
  • 98
Vadims Krutovs
  • 197
  • 2
  • 3

1 Answers1

0

I have the same issue, here a working snippet with Xcode 11 Beta 5, SwiftUI, AwaitKit, PromiseKit and Firestore.

import Foundation
import Firebase
import PromiseKit
import AwaitKit


final class UserStore: ObservableObject {
    let collection: CollectionReference

    init() {
        collection = Firestore.firestore().collection("users")
    }


    func create(userId: String, familyName: String, givenName: String, email: String) {
         async {
            let fetchUser : Promise<String> = Promise { seal in
                self.collection.document("HFlTjPHgbXH96q6LQ93N").getDocument { (document, error) in
                    if let document = document, document.exists {
                        let dataDescription = document.data().map(String.init(describing:)) ?? "nil"
                        seal.fulfill(dataDescription)
                    } else {
                        seal.reject(NSError())
                    }
                }
            }
            let user = try! await(fetchUser)
            print("My user:", user)
        }
    }
}


Thibaut Mottet
  • 414
  • 4
  • 15