downloadURL()' is deprecated: Use `StorageReference.downloadURLWithCompletion()` to obtain a current download URL.?
The error says that you need to use StorageReference.downloadURLWithCompletion()
well you need to use it:
let storageItem = Storage.storage().reference().child(ImageUid)
storageItem.putData(ImageData, metadata: metadata) { (metadata, error) in
if error != nil {
print("Couldn't Upload Image")
} else {
print("Uploaded")
storageItem.downloadURL(completion: { (url, error) in
if error != nil {
print(error!)
return
}
if url != nil {
self.SetUpUser(Image: url!.absoluteString)
}
}
}
}
Firebase Storage Warning: downloadURL()' is deprecated: Use `StorageReference.downloadURLWithCompletion()
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
}
})
Update for metadata?.downloadURL().absoluteString that returns a String
The metadata.downloadURL
no longer exists (and hasn't existed in SDKs released since May 2018). To get the download URL you now have to call downloadURL()
on the storage reference and then use the URL in the callback.
So the place to put your own code that needs the download URL is right where it now says //Do something with url
in the code you got from the documentation. If you want to pass that URL to your `` method, that'd looks something like:
storageRef.putData(imageData, metadata: nil, completion: {(metadata, error) in
if error != nil {
ProgressHUD.showError(error!.localizedDescription)
return
}
//*********** Need to fix this **************
let photoUrl = storageRef.downloadURL(completion: {url, error in
if error != nil {
print("Failed to download url:", error!)
return
} else {
self.sendDatatoDatabase(photoUrl: url)
}
})
})
Kingfisher: Ambiguous use of 'setBackgroundImage(with:for:placeholder:options:progressBlock:completionHandler:)'
That error is because you need to handle the completionHandler
instead of passing nil
. Try below code:
button.kf.setBackgroundImage(with: URL(string: picture), for: .normal, placeholder: nil, options: options, progressBlock: nil) { result in
// result is either a .success(RetrieveImageResult) or a .failure(KingfisherError)
switch result {
case .success(let value):
// The image was set to image view:
print(value.image)
// From where the image was retrieved:
// - .none - Just downloaded.
// - .memory - Got from memory cache.
// - .disk - Got from disk cache.
print(value.cacheType)
// The source object which contains information like `url`.
print(value.source)
case .failure(let error):
print(error) // The error happens
}
}
Firebase storage downloadURL partial apply forwarder for @nonobjc message
have a look at it I am here uploading a profile image to firebase storage
if let uploadData = UIImagePNGRepresentation(self.profileImageView.image!) {
storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
if let error = error
{
print(error)
return
}
else
{
//get download url if upload is successful
let downloadURL = metadata?.downloadURL()?.absoluteString
print(downloadURL!)
}
})
}
Related Topics
Com.Facebook.Sdk Error 2 on iOS
Xcode 5/iOS 7 - Localization Not Working in Simulator
Using Sysctlbyname() from Swift
Apple MACh-O Linker (Id) Warning:Building for MACosx, But Linking Against Dylib Built for iOS
Uitableviewcellaccessorycheckmark and Autolayout Constraints
Programmatically Highlight Uibarbuttonitem
Simple Uitableview in Swift - Unexpectedly Found Nil
Enable Uialertaction of Uialertcontroller Only After Input Is Validated
iOS 7 When Rotating View in Tab Bar, Right Side of View Is Not Clickable
Static VS Class as Class Variable/Method (Swift)
Enforce Collectionview to Have Only 2 Rows
Horizontally Scroll All Rows of Uicollectionview Together
Change Tabview Color Based on Which Tab Is Selected -Swiftui
Send an Email from My App Without Using Mfmailcomposeviewcontroller
Obtaining Weights in Cvsvm, the Svm Implementation of Opencv
Using iOS 6 Theme for iOS 7 App
Creating an Image Format with an Unknown Type Is an Error Objective-C Xcode 8