gpt4 book ai didi

ios - 它抛出这个错误 : Value of type 'StorageMetadata' has no member 'downloadURL'

转载 作者:行者123 更新时间:2023-11-28 11:41:22 25 4
gpt4 key购买 nike

我需要有关此编码的帮助,我不确定发生了什么。请不要重复这个问题或类似问题,因为我已经在互联网上尝试过任何解决方案,但没有任何效果。我正在尝试获取“上传后访问下载 URL”的权限。

我尝试过:我使用元数据的自动完成功能,它显示没有 url 选项,我得到的最接近的是 metadata.path 或 metadata.storageReference。

第二次尝试:我知道 API 在 5.0.0 版本中发生了变化,所以我使用 StorageReference 的 downloadURL 方法。这也给了我一个错误,也许我把它放在了错误的代码行或者其他地方。

这是类(class):-

import UIKit
import Firebase
import FirebaseDatabase
import FirebaseStorage
import SwiftKeychainWrapper

class SignUpVC: UIViewController, UIImagePickerControllerDelegate,UINavigationControllerDelegate{

@IBOutlet weak var userImagePicker: UIImageView!
@IBOutlet weak var userNameField: UITextField!
@IBOutlet weak var SignUpBtn: UIButton!

var userId: String!
var emailField: String!
var passwordField: String!
var imagePicker: UIImagePickerController!
var imageselected = false
var userName: String!

//Do any Additional SetUp after loading the view
override func viewDidLoad() {
super .viewDidLoad()

imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
}
override func viewDidAppear(_ animated: Bool) {

if let _ = KeychainWrapper.standard.string(forKey: "uid") {
performSegue(withIdentifier: "ToMessges", sender: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage{
userImagePicker.image = image
imageselected = true
}else{
print("Image wasent selected!")
imagePicker.dismiss(animated: true, completion: nil)
}
}
func setuser(img: String){
let userData = [
"username": userName!,"userimage": img]
KeychainWrapper.standard.set(userId, forKey: "uid")
let location = Database.database().reference().child("users").child(userId)
location.setValue(userData)
dismiss(animated: true, completion: nil)
}

func uploadImg (){
if userNameField.text == nil {
SignUpBtn.isEnabled = false

}else {
userName = userNameField.text
SignUpBtn.isEnabled = true
}

guard let img = userImagePicker.image, imageselected == true else {
print("Image needs to be selected")

return
}

if let imgData = img.jpegData(compressionQuality: 0.2) {

let imgUid = NSUUID().uuidString
let metadata = StorageMetadata()
metadata.contentType = "image/Jpeg"
Storage.storage().reference().child(imgUid).putData(imgData, metadata:metadata){(metaData,error
) in

if error != nil {
print("Did not upload Image!")

}else {
print("Uploaded")

let downloadURL = metadata.downloadURL()?.absoulteString //error here

if let url = downloadURL {
self.setUser(img:url)
}
}
}
}
}

最佳答案

根据 Firebase doc ,您可能在 StorageMetadata 类中没有直接属性 downloadURL。因此,您可能必须使用 dictionaryRepresentation 并使用 mediaLink 访问下载链接键。

例子:

if let downloadURL = metadata.dictionaryRepresentation()["mediaLink"] as? String{

self.setUser(img:downloadURL)
}

关于ios - 它抛出这个错误 : Value of type 'StorageMetadata' has no member 'downloadURL' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53551411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com