I am using Amazon S3 to store profile pictures for user accounts on an iOS app using swift.. I am able to get the pictures I want from S3, but it takes a very long time for them to load. I don't know why this is happening. Is that just how S3 works, or is there a better way to do things? This is my code for downloading the picture:
let downloadingFilePath1 = NSTemporaryDirectory().stringByAppendingPathComponent("temp-download")
let downloadingFileURL1 = NSURL(fileURLWithPath: downloadingFilePath1)
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
let readRequest1 : AWSS3TransferManagerDownloadRequest = AWSS3TransferManagerDownloadRequest()
readRequest1.bucket = "groopapictures"
readRequest1.key = self.searchTextField.text
readRequest1.downloadingFileURL = downloadingFileURL1
transferManager.download(readRequest1).continueWithBlock { (task) -> AnyObject! in
println(task.error)
if task.error == nil {
self.ppImageView.hidden = false
println("Fetched image")
self.ppImageView.image = UIImage(contentsOfFile: downloadingFilePath1)
}
return nil
}
Any help would be appreciated!
Check which queue you're running on in your return block. If it's not the main queue, setting the image
property of a UIImageView
can take a long time to be "noticed" and updated. Test this by putting the image assignment line inside a dispatch_async()
to the main thread.
If that doesn't help, run Charles and see how long S3 is taking to return the image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With