当我从手机上传图片时,应用程序崩溃并且出现错误
'FIRInvalidArgumentException', reason: 'Unsupported type: NSURL (found in field AccountTypeImageURL)'
这是包含相关代码的函数
func submitButtonADD(){
let imageName = NSUUID().uuidString
let storageRef = Storage.storage().reference().child("Account Type Images").child("\(imageName)png")
let sRef = Storage.storage().reference().child("Account Type Images").child("\(imageName)png")
guard let uid = Auth.auth().currentUser?.uid else { return }
if let uploadData = UIImagePNGRepresentation(self.profileImageView.image!) {
storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
if let error = error {
print(error)
return
}
sRef.downloadURL { url2, error in
if let error = error {
print(error)
} else {
// Get the download URL for 'images/stars.jpg'
let db = Firestore.firestore()
db.collection("Users").document(uid).setData(["AccountTypeImageURL": url2],merge: true)
}
}
})
}
}
最佳答案
该错误会准确地告诉您您尝试将 NSURL
类型保存到不受支持的 Firestore
文档中时出了什么问题。所以将 url 转换为字符串,然后像这样将其保存在 Firestore 中:
db.collection("Users").document(uid).setData(["AccountTypeImageURL": url2.absoluteString],merge: true)
关于 swift 'FIRInvalidArgumentException' ,原因 : 'Unsupported type: NSURL (found in field AccountTypeImageURL)' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50624805/