Firebase Storage Warning: downloadURL()' is deprecated: Use `StorageReference.downloadURLWithCompletion()

后端 未结 2 556
梦如初夏
梦如初夏 2020-12-10 19:07

I just updated my project to the latest version of Firebase Storage and I am now getting a warning: downloadURL() is deprecated: Use StorageReference.downloadURLWithComplet

相关标签:
2条回答
  • 2020-12-10 20:04

    I had the same problem, but I fixed it with this code:

        uploadTask.observe(.success) { snapshot in
            guard let imageURL = snapshot.metadata?.storageReference?.downloadURL(completion: { (url, error) in if error != nil {
                print(error as Any)
            } else {                      //add all you want
    
                }
            }) else { return }
            let imageStr = String(describing: imageURL)
            DBService.manager.updatePhoto(profileImageUrl: imageStr)
            AuthService.manager.updatePhoto(urlString: imageStr)
        }
    
    }
    
    0 讨论(0)
  • 2020-12-10 20:08

    Basically not using the metadata but instead just getting the url after the success of your observe event. Since it's successful and you know it's there, you can download the URL. It's there in their docs to 'Generate a download URL'. Below, I'm assuming your StorageReference is uploadProfilePicTask.

    uploadProfilePicTask.downloadURL(completion: { (url, error) in
                        if (error == nil) {
                            if let downloadUrl = url {
                               // Make you download string
                               let downloadString = downloadUrl.absoluteString
                            }
                        } else {
                       // Do something if error
                        }
               })
    
    0 讨论(0)
提交回复
热议问题