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.
ViewWillAppear()
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() } } }
, a) , : b) , c) , d) "".:)
, " iPhone" - iPhone 6s, , 4032 x 3024. , imageView . Firebase , , , .
, downloadURL SDWebImage, PINRemoteImage AlamoFireImage, , . , , , , , View .
downloadURL
SDWebImage
PINRemoteImage
AlamoFireImage
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() } })
Source: https://habr.com/ru/post/1651910/More articles:A task statement in Java that returns the first completion task - javaReconfiguration of the print {0, 1, 2, 3} by a multi-threaded program (C ++) - c ++Django Rest Framework get_queryset called more than once - django-rest-frameworkCan numpy argsort give an equal element of the same rank? - pythonSymfony Console - create a file? - phpRuby ERB - создайте метод content_for - rubyNg-bootstrap Angular 2 import error - angularjsAlternative to replacing Span with Android - androidAngular2 + ng-bootstrap Example - javascriptPHP alternative for NodeJS? - javascriptAll Articles