我在执行changeRequest时遇到了麻烦。我一直收到错误“类型的值'StorageMetadata'没有成员'downloadURL'”。我不确定发生了什么,或者它是否已从StorageMetadata中弃用。我很快乐,我真的不知道从哪里拿走它。一切都有帮助。谢谢!
import Foundation
import Firebase
import FirebaseAuth
import FirebaseStorage
import FirebaseDatabase
struct FirebaseService {
let dbRef = Database.database().reference()
let storageRef = Storage.storage().reference()
private func saveInfo(user: User!, username: String, password: String, city: String, state: String, bio: String) {
//Create User Dictionary Info
let userInfo = ["email": user.email!, "username": username, "city": city, "state": state, "bio": bio, "uid": user.uid, "photoUrl": String(describing: user.photoURL!)]
//Create User Reference
let userRef = dbRef.child("users").child(user.uid)
// Save User Info in Database
userRef.setValue(userInfo)
//SIGN IN THE USER
signIn(email: user.email!, password: password)
}
func signIn(email: String, password: String) {
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
if error == nil {
if let user = user {
print("\(user.user.displayName) has signed in successfully!")
}
} else {
print(error!.localizedDescription)
}
})
}
private func setUserInfo(user: User!, username: String, password: String, city: String, state: String, bio: String, data: NSData!) {
//CREATE PATH FOR USER IMAGE
let imagePath = "profileImage\(user.uid)/userPic.jpg"
//CREATE IMAGE REFERANCE
let userImageRef = storageRef.child(imagePath)
//Create MetaData for the Image
let metaData = StorageMetadata()
metaData.contentType = "image/jpeg"
//Save the user Image in the Firebase Storage File
userImageRef.putData(data as Data, metadata: metaData) { (metaData, error) in
if error == nil {
let changeRequest = user.createProfileChangeRequest()
changeRequest.displayName = username
changeRequest.photoURL = metaData?.downloadURL()
} else {
print(error!.localizedDescription)
}
}
}
}