嘿,我需要这个编码的帮助,我不知道发生了什么。前几天起作用了。错误出现在if let ur; = metaData?.downladURL()
func uploadProfileImage(_ image:UIImage, completion: @escaping ((_ url:URL?)->())) {
guard let uid = Auth.auth().currentUser?.uid else { return }
let storageRef = Storage.storage().reference().child("user/\(uid)")
guard let imageData = UIImageJPEGRepresentation(image, 0.75) else { return }
let metaData = StorageMetadata()
metaData.contentType = "image/jpg"
storageRef.putData(imageData, metadata: metaData) { metaData, error in
if error == nil, metaData != nil {
if let url = metaData?.downloadURL() {
completion(url)
} else {
completion(nil)
}
// success!
} else {
// failed
completion(nil)
}
}
}
// MARK: - handleRegister
func handleRegister() {
guard let email = emailTextField.text, let password = passwordTextField.text, let name = nameTextField.text else {
print("Error")
return
}
Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
if error != nil {
// print("Error")
return
}
// MARK: - hadleLogin//
guard let uid = Auth.auth().currentUser?.uid else {
return
}
// MARK: - image successful authenficated user
let imageName = NSUUID().uuidString
let storageRef = Storage.storage().reference().child("profile_images").child("\(imageName).png")
if let profileImageUrl = self.profileImageView.image, let uploadData = UIImageJPEGRepresentation(self.profileImageView.image!, 0.1) {
storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
if error != nil, metadata != nil {
print(error ?? "")
return
}
storageRef.downloadURL(completion: { (url, error) in
if error != nil {
print(error!.localizedDescription)
return
}
if let profileImageUrl = url?.absoluteString {
let values = ["name": name, "email": email, "profileImageUrl": profileImageUrl]
self.registeUserIntoDatabaseWithUID(uid: uid, values: values as [String : AnyObject])
}
})
})
}
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。