Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从firebase数据库设置配置文件映像_Ios_Image_Firebase_Firebase Realtime Database_Uiimageview - Fatal编程技术网

Ios 如何从firebase数据库设置配置文件映像

Ios 如何从firebase数据库设置配置文件映像,ios,image,firebase,firebase-realtime-database,uiimageview,Ios,Image,Firebase,Firebase Realtime Database,Uiimageview,嘿,我是Xcode新手,需要帮助将我的配置文件图像从firebase数据库上传到我的用户配置文件。到目前为止,我没有收到任何错误,但是当我的用户登录时,图像没有显示,图像已经存储在firebase中,但是当我将UIImageView附加到用户配置文件时,图像显示为空白。是否有人有解决方案来修复此代码,以便在登录后将我的图像显示在用户配置文件上?应该是自动的 typealias blockCompletedWith = (Bool, String) -> Voi

嘿,我是Xcode新手,需要帮助将我的配置文件图像从firebase数据库上传到我的用户配置文件。到目前为止,我没有收到任何错误,但是当我的用户登录时,图像没有显示,图像已经存储在firebase中,但是当我将UIImageView附加到用户配置文件时,图像显示为空白。是否有人有解决方案来修复此代码,以便在登录后将我的图像显示在用户配置文件上?应该是自动的

               typealias blockCompletedWith = (Bool, String) -> Void


               //path: folder name if any followed by name of image
  func uploadImageToFirebaseStorage(data: Data, path: String, blockCompletedWith: @escaping blockCompletedWith) {
                     let metadata = StorageMetadata()
                      metadata.contentType = "profileImage.jpg"

                    let store = Storage.storage()
                    let storeRef = store.reference().child(path)
                    let _ = storeRef.putData(data, metadata: metadata) { (metadata, error) in
                       guard let _ = metadata else {
                       print("error occured: \(error.debugDescription)")
                            blockCompletedWith(false, "")
                                    return
                                                  }

                storeRef.downloadURL(completion: { (url, error) in
                     if let urlText = url?.absoluteString {
                     blockCompletedWith(true, urlText)
                                                      }
                                             else {
                                blockCompletedWith(false, "")
                                                      }
                                                  })
                                              }
                                          }


               if let profileImageUrl = dictionary?["gs://tunnel-vision-d6825.appspot.com"] as? String {
                  let url = URL(string: profileImageUrl)
                       URLSession.shared.dataTask(with: url!) { (data, response, error) in
                               if let error = error{
                               print("Error : \(error)")
                    return
                                }
                                    DispatchQueue.main.async {
                                    self.ProfileImage.image = UIImage(data: data!)
                                            }
                    }.resume()

                        }

使用firebase存储保存图像并将图像链接放入数据库

typealias blockCompletedWith = (Bool, String) -> Void

func uploadProfileImage(_ image: UIImage) {
        let imageData = image.jpegData(compressionQuality: 1.0)
        let path = "folderName/imagename.jpeg"
        self.uploadImageToFirebaseStorage(data: imageData!, path: path, blockCompletedWith: { (isSuccess, urlStr) in
            Utility.stopActivityIndicator()
            DispatchQueue.main.async {
                if isSuccess {
                    print(urlStr)
                }
                else {
                    print("Error in uploading Image")
                }
            }
        })
    }
-----------上传ImageToFirebaseStorage方法------------


what is(self.uploadImageToFirebaseStorage)@MohitKumarThis行调用答案中写入的第二个方法。我已经用清晰的分隔更新了答案。现在清楚了吗?是的,我明白了,但如何修复此错误(“ProfileViewController”类型的值没有成员“uploadImageToFirebaseStorage”)@MohitKumar只需复制第二个方法并粘贴到视图控制器中。图像仍然没有出现@MohitKumar
//path: folder name if any followed by name of image
func uploadImageToFirebaseStorage(data: Data, path: String, blockCompletedWith: @escaping blockCompletedWith) {
        let metadata = StorageMetadata()
        metadata.contentType = "image/jpeg"

        let store = Storage.storage()
        let storeRef = store.reference().child(path)
        let _ = storeRef.putData(data, metadata: metadata) { (metadata, error) in
            guard let _ = metadata else {
                print("error occured: \(error.debugDescription)")
                blockCompletedWith(false, "")
                return
            }

            storeRef.downloadURL(completion: { (url, error) in
                if let urlText = url?.absoluteString {
                    blockCompletedWith(true, urlText)
                }
                else {
                    blockCompletedWith(false, "")
                }
            })
        }
    }