BhaviDev
BhaviDev

Reputation: 194

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.

Upvotes: 2

Views: 4752

Answers (6)

Remon Atef
Remon Atef

Reputation: 41

For Swift 4 (Working Perfectly)

PLEASE INSTALL THIS PODS FIRSTLY:

pod 'Firebase/Storage'
pod 'SDWebImage', '~> 4.0'
pod 'FirebaseUI/Storage'

Then in your Xcode 9+:

import FirebaseStorage
import SDWebImage
import FirebaseUI


let reference = Storage.storage().reference(withPath: "your image path")
let imageView: UIImageView = self.imageView
imageView.sd_setImage(with: reference)

Upvotes: 0

Emily Fung
Emily Fung

Reputation: 141

  1. Add a BridgingHeader.h file to your project with this:
#import <FirebaseStorageUI.h>
  1. Then in your class:
import UIKit
import FirebaseStorageUI // <-- don't forget to import this

func getImage() {

    let reference = storageRef.child(imageFileName)

    myImageView.sd_setImage(with: reference, placeholderImage: UIImage(named: "bg"), completion: { (image, error, cacheType, storageRef) in
            //...
        })
}

Upvotes: 2

aniket.ghode
aniket.ghode

Reputation: 86

FirebaseUi has come up with their own little extension for SDWebImage.

Just add following pod in your Podfile

pod 'FirebaseUI/Storage'

And Use following line of code to cache image with the Firebase Storage Reference.

// Load the image using SDWebImage
[imageView sd_setImageWithStorageReference:reference placeholderImage:placeholderImage];

Hope this will help you.

Upvotes: 4

shafi
shafi

Reputation: 456

I resolved this issue by implementing the other method of SDWebImage

SDWebImageManager.shared().downloadImage(with:"Your Firebase Url", options: .refreshCached, progress: nil, completed: { (image, error, cache, isDownloader, url) in
    if image != nil { 
        YourImageView.image = image       
     }
})

This is in Swift but you can implement it in Objective-C.

Here is a link:
https://github.com/rs/SDWebImage/issues/845

Upvotes: 2

Reshad
Reshad

Reputation: 2652

Don't forget to import the SDWebImage module like this (Swift)

@import SDWebImage

Or for Obj-C

#import <SDWebImage/UIImageView+WebCache.h>

Upvotes: 0

CodeChanger
CodeChanger

Reputation: 8381

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.

Upvotes: 1

Related Questions