Search code examples
iosobjective-cfirebasefirebase-storagesdwebimage

SDWebImage not working with Firebase storage image download


I am working with one project which uses Firebase storage API and getting some image from Firebase.

Working fine with NSData logic with download image from server and show it into my app.

But same thing is not working through SDWebImage SDK as I need to combine firebase url in SDWebImage as firebase docs also mention to bind this and use to download images fro. Storage through SDWebImage

Below is my cod ewhixh is not working my app.

FIRStoragereference *ref = [[FIRStorage storage] referenceWithPath:myfilepath];

[Cell.imgDetail sd_setImageWithStorageReference:ref placeholderImage:nil completion:^(UIImage *image,

}];

Error : method not found in sd web image

Please help me I am stuck here.


Solution

  • I have used firebase withSDWebImage and you can use below method for StorageReference

    For this Method you need to add one category file for UIImageView

    #import "UIImageView+FirebaseStorage.h"
    

    You can find this file here at FireBaseUIIOS

    FIRStorageReference *storageRef = [[FIRStorage storage]
                                               referenceWithPath:[NSString stringWithFormat:@"/Folder/images/%@",<IMAGE_NAME>]];
    
    
            [cell.imgDetail sd_setImageWithStorageReference:storageRef
                                           placeholderImage:nil
                                                 completion:^(UIImage *image,
                                                              NSError *error,
                                                              SDImageCacheType
                                                              cacheType,
                                                              FIRStorageReference *ref) {
                                                     if (error != nil) {
                                                         NSLog(@"Error loading image: %@", error.localizedDescription);
                                                     }
                                                 }];
    

    Also you can use above @Shafi's method of SDWebImage but for that you need to provide full url of firebase storage like below.

    Full URL : storageRef.fullPath

    Hope this will helps you.