IOS - memory loading for Firebase is very slow

I am using Firebase Storage for my application. In my application, the user has a profile and can upload a profile photo, and then, when he clicks on his profile in the future, he must download and display the image of his profile. The problem is that when downloading and uploading a photo, there is a significant delay, and it seems that the code does not work when necessary. For the download, I have a call in mine ViewWillAppear(), however it continues to work even after the screen loads, and I click on other things. How can I speed this up? Not only is the delay annoying, but it crashes when I switch to a different view or logout and the code ViewWillAppear()still works.

override func viewWillAppear(bool: Bool) {

    var retPic : UIImage
    let storage = FIRStorage.storage()

    let storageRef = storage.referenceForURL("gs://project-xxxxxxxxxxx.appspot.com")

    let profPicRef = storageRef.child("images/" + (FIRAuth.auth()?.currentUser?.uid)! + ".jpg")
    // Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes)

    profPicRef.dataWithMaxSize(1 * 4096 * 4096) { (data, error) -> Void in
        if (error != nil) {
            print(error)
        } else {
            // Data for "images/island.jpg" is returned
            print("This is delayed")
            self.retPic = UIImage(data: data!)!
            self.imageView.image = self.retPic
                     print("still here")
            self.imageView.reloadInputViews()   
        }
    }
}
+4
2

, a) , : b) , c) , d) "".:)

, " iPhone" - iPhone 6s, , 4032 x 3024. , imageView . Firebase , , , .

, downloadURL SDWebImage, PINRemoteImage AlamoFireImage, , . , , , , , View .

+1

NSData UIImage URL- Kingfisher. .

Swift3:

import Kingfisher

profPicRef.downloadURL(completion: { (url, error) in

   if error != nil {

       print(error)
   }
   else{

       let retPicUrl = (url?.absoluteString)! as String

    self.imageView.kf.setImage(with: URL(string: retPicUrl)!)
    self.imageView.reloadInputViews() 

   }
 })
-1

Source: https://habr.com/ru/post/1651910/


All Articles