Why aren't my Firebase Storage URLs uploading to Google Cloud Firestore?

后端 未结 1 1973
礼貌的吻别
礼貌的吻别 2021-01-15 05:06

I am trying to allow users to upload a profile photo to Firebase Storage. The image gets uploaded during the sign up process of my app. The image is being uploaded to Fireba

相关标签:
1条回答
  • 2021-01-15 05:23

    You can't use a return statement for a function that contains a closure as the function will return before the closure has executed.

    Instead change your function to use a completion handler such as

    func uploadProfilePic(completion: @escaping (String?, Error?) -> ()) {
    

    Then once you get your download url call the handler.

        profilePhotosRef.downloadURL { (url, err) in
          completion(url, err)
        }
    

    You can then use this function to populate your call to Cloud Firestore like so

       self.uploadProfilePic() { (url, error) in
    
        guard error....
    
        if let url = url {
          // do your upload here
        }
    }
    
    0 讨论(0)
提交回复
热议问题