I'm building an app where a user can update his profile picture using firebase services (firebase storage).
In my app user can have multiple friends, and pictures of his friends is displayed in a view controller.
What I want to achieve is that when user updates his profile picture all his friends (connected using other devices) get his image changed in a real time.
For that I believe that the easiest solution is to watch the changes in the storage.
Here is the code I used to upload the user image
let storage = FIRStorage.storage()
let storageref = storage.reference(forURL: "my firebase url")
let imageref = storageref.child("images")
let userid : String = (user.uid)
let spaceref = imageref.child("\(userid).jpg")
let imageConverter = ImageConverter()
var profilePicture : UIImage = imageConverter.cropToBounds(image: self.profilePicture.image!, width: 150 ,height: 150)
profilePicture = imageConverter.resizeImage(image: profilePicture, targetSize: CGSize(width: 140, height: 150))
let imageData = UIImagePNGRepresentation(profilePicture)
_ = spaceref.put(imageData!, metadata: nil){ metadata, error in
if (error != nil) {
loadingScreenViewController.view.removeFromSuperview()
self.alert(title: "Error", description: "please check your internet connection and try again")
}
else {
_ = metadata!.downloadURL
}
loadingScreenViewController.view.removeFromSuperview()
Does anyone have an idea about how to watch changement in firebase storage.
I get the image simply by using
let imageRef = storage.child("images/\(friendsManager.friends[indexPath.row].id).jpg")