Created
August 4, 2018 11:13
-
-
Save atanasovdejan/ffe4396ac9f715447ae3b6de9aec821d to your computer and use it in GitHub Desktop.
Update Profile Picture and Display Name in Firebase User
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func updateProfileInfo(withImage image: Data? = nil, name: String? = nil, _ callback: ((Error?) -> ())? = nil){ | |
guard let user = Auth.auth().currentUser else { | |
callback?(nil) | |
return | |
} | |
if let image = image{ | |
let profileImgReference = Storage.storage().reference().child("profile_pictures").child("\(user.uid).png") | |
_ = profileImgReference.putData(image, metadata: nil) { (metadata, error) in | |
if let error = error { | |
callback?(error) | |
} else { | |
profileImgReference.downloadURL(completion: { (url, error) in | |
if let url = url{ | |
self.createProfileChangeRequest(photoUrl: url, name: name, { (error) in | |
callback?(error) | |
}) | |
}else{ | |
callback?(error) | |
} | |
}) | |
} | |
} | |
}else if let name = name{ | |
self.createProfileChangeRequest(name: name, { (error) in | |
callback?(error) | |
}) | |
}else{ | |
callback?(nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment