Предполагая, что ваша проблема, вероятно, следующая
storage.child(channelID).child(imageName).putData(data, metadata: metadata) { meta, error in
completion(meta?.downloadURL())
}
Ответ, быстрый 4
storage.child(channelID).child(imageName).putData(data, metadata: metadata) { metaN, error in
// then we check if the metadata and path exist
// if the error was nil, we expect the metadata and path to exist
// therefore if not, we return an error
guard let metadata = metaN, let path = metadata.path else {
completion(nil)
return
}
// now we get the download url using the path
// and the basic reference object (without child paths)
self.getDownloadURL(from: path, completion: completion)
}
private func getDownloadURL(from path: String, completion:@escaping (URL?) -> Void) {
let firebaseStorageUrl = "gs://yourApp-Firebase-Storage.appspot.com"
let storageReference = Storage.storage().reference(forURL: firebaseStorageUrl)
storageReference.child(path).downloadURL { (url, error) in
completion(url)
}
}
Убедитесь, что вы включили хранилище в Firebase, и проверьте ошибки консоли в случае сбоя