swift 'FIRInvalidArgumentException' ,原因 : 'Unsupported type: NSURL (found in field AccountTypeImageURL)'

标签 swift xcode google-cloud-firestore

当我从手机上传图片时,应用程序崩溃并且出现错误

'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/

相关文章:

ios - 为什么核心数据中的文件仍然存在,尽管我可以在核心数据中成功删除对象

ios - 在 xcode 6 中排序文档大纲

javascript - 有没有一种方法可以确定 firebase 数据库中的所有集合是否为空?

flutter - 从Flutter中的Firestore检索数据后为空列表

ios - 使用 Swift for iOS 实现 Google Classroom API 时遇到问题 : Possible missing bridging header file

ios - 如何在 iOS swift 中获取 1 小时前的日期?

ios - Swift:字典键包含值仍然是错误零

ios - 缺少营销图标 Xcode bug?

angular - 错误 NG6002 : Appears in the NgModule. 导入 AppModule,但无法解析为 NgModule 类

ios - Swift 中可选和非可选函数参数之间的语义和最佳用例