Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to store image in cache in iOS?

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 452
    Comment on it

    Hi Readers,

    This blog includes the concept of how to store image data in a cache memory with the help of SDWebImageManager. First of all, we need to install pods in the application to use SDWebImageManager, after creation of pod file you need to include two lines in the pod file which are given below:-

    platform :ios, 9.0
    pod 'SDWebImage', '~>3.8'

     


    After pod file installation process you also need to import file  which is given below:-

    #import <SDWebImage/UIImageView+WebCache.h>

     


    Now given below is the code to store image information in cache memory:-

    NSString *imageString=@"http://www.istonsoft.com/blog/wp-content/uploads/2015/03/ios.png";
        NSURL *imageURL=[[NSURL alloc]initWithString: imageString];
        SDWebImageManager *imageManager = [SDWebImageManager sharedManager];
        [imageManager downloadImageWithURL:imageURL
                              options:0
                             progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                                 // progression tracking code
                             }
                            completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                                if (image) {
                                    // you can also view image in UIImageView according to your need
                                    NSLog(@"%@",image);
                                }
                            }];

     

    Use of storing an image in a cache is that next time when you will execute the application you will get an array of a downloaded image so from a cache that image will be fetched and take less time for execution.

    Hope this code will help you to store image information in cache memory.

 2 Comment(s)

  • In the same above am using in my app but it's not working us. .am making chat app. Here in chatwith user controller if I send image to user it's showed empty image cell . Then that image has shown after scrolling table view..how I resolve it..

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: