如何正确更新个人资料图像

问题描述 投票:0回答:1

如何正确上载用户profileImage,尝试更新用户profileImage时出现错误。

如何解决此错误?

线程1:致命错误:展开一个可选值时意外发现为零'

**URLSession.shared.dataTask(with: url!) { (data, response, error) in**

这是完整代码

DatabaseRef.child("users").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
                // Get user value
                let value = snapshot.value as? NSDictionary
                let username = value?["username"] as? String ?? "username"
               let dict: Dictionary<AnyHashable, Any>? = ["photo": "url of photo"]

                if let profileImageUrl = dict?["photo"] as? String {
let url = URL(string: profileImageUrl)
                    URLSession.shared.dataTask(with: url!) { (data, response, error) in
                        if error != nil{
                            print(error!)
                            return
                        }
ios swift firebase user-profile
1个回答
0
投票

您应始终避免强行打开包装。相反,您可以检查url是否不为零,并且仅在url具有某些值时才发送请求。

© www.soinside.com 2019 - 2024. All rights reserved.