我正在我的应用程序的编辑配置文件部分中工作。当我尝试更改和更新用户个人资料照片时。应用程序崩溃了,我得到了这个错误
reason: 'URL scheme must be one of gs://, http://, or https://
当我创建新的个人资料并添加个人资料照片时,或者如果我上传照片,效果很好,但是当我尝试更改个人资料照片时,我得到了。它将首先删除个人资料照片并进行更新(当用户没有照片时,图像视图变为灰色),然后当我尝试再次更改照片时,它将崩溃。
这是我的代码。
func updateProfileImage() {
guard imageChanged == true else { return }
guard let currentUid = Auth.auth().currentUser?.uid else { return }
guard let user = self.user else { return }
Storage.storage().reference(forURL: user.profileImageUrl).delete(completion: nil)
let filename = NSUUID().uuidString
guard let updatedProfileImage = profileImageView.image else { return }
guard let imageData = updatedProfileImage.jpegData(compressionQuality: 0.3) else { return }
STORAGE_PROFILE_IMAGES_REF.child(filename).putData(imageData, metadata: nil) { (metadata, error) in
if let error = error {
print("Failed to upload image to storage with error: ", error.localizedDescription)
}
STORAGE_PROFILE_IMAGES_REF.downloadURL(completion: { (url, error) in
USER_REF.child(currentUid).child("profileImageUrl").setValue(url?.absoluteString, withCompletionBlock: { (err, ref) in
guard let userProfileController = self.userProfileController else { return }
userProfileController.fetchCurrentUserData()
self.dismiss(animated: true, completion: nil)
})
})
}
}
}
答案 0 :(得分:0)