mercredi 22 juin 2016

iOS: Downloading the AWS S3 images & cache it for future use

I have been pulling my hair out from Morning on trying to download the images (webp image) from Amazon S3 bucket and cache it. Whatever the approach I took, I have hit some or the other road block. Different ways I tried to achieve this,

  1. Subclassing NSURLProtocol & Using the SDWebImage to retrieve the image as shown in the blog post here. The problem with this approach is that, the canInitWithRequest method of the subclassed protocol will never get called even tough I have registered my subclassed NSURLProtocol class.
  2. Planned to use the SDWebImage and other libraries directly, but we can't do that since there is no provision to set the Authorization headers in SDWebImage, even tough if we try setting it, SDWebImage will ignore it while creating an NSMutableURLRequest for downloading.

So right now I am left with an option either to use the Amazon SDK to download the image and then cache it using the SDWebImage's SDImageCache independently, or I need to add the SDWebImage source code to my project and then I need to modify it's source to take the authorization header.

Please let me know if there's any better way to achieve this, it'd be great if I could some pointers on what'd be the best way to achieve what I am trying to do.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire