SDWebImage / SDWebImageSVGCoder

A SVG coder plugin for SDWebImage, using Apple's built-in framework
MIT License
103 stars 34 forks source link

Not refreshed Image #12

Closed ablyBikramjeet closed 4 years ago

ablyBikramjeet commented 4 years ago

Hello Team,

Thanks a lot for make a good library for SVG images.

I want to show both .SVG and any-other type of image. I have showed images successfully but the problem is when i update the image from server but am showing previous image. Run time changed images not working. Please suggest me how i can show new images at run time. Thanks.

dreampiggy commented 4 years ago

This because SDWebImage’s cache system, by default use an agressive cache control based on Native code’s expiration age and size. It does not follow any HTTP cache control like Cache-Control Etag...

For this case, you can use the .refreshCached option, which will use the HTTP cache control, if your server update the remote resource, the exist cache will be replaced

ablyBikramjeet commented 4 years ago

Thanks for your quick response.

I am explaining you please help me :-

Suppose I have used cell.cuisinesImageView.sd_setImage(with: cellVM.cuisineImageURL). and all images comes in without .svg format. In this case everything working fine.

But I want to show .SVG images and put the below code

let SVGCoder = SDImageSVGCoder.shared SDImageCodersManager.shared.addCoder(SVGCoder) cell.cuisinesImageView.sd_setImage(with: cellVM.cuisineImageURL)

In this case nothing happed always previous image shows.

So please tell me how I can resolve this problem.

ablyBikramjeet commented 4 years ago

One more thing .svg image not showing as original these are. From backend I got coloured images but when i shows in my code in is showing black and white. How I resolved this issue also. Screenshot 2019-11-26 at 6 11 22 PM

Screenshot 2019-11-26 at 6 11 12 PM

dreampiggy commented 4 years ago

let SVGCoder = SDImageSVGCoder.shared SDImageCodersManager.shared.addCoder(SVGCoder)

This code is the setup code, you should always put it on the AppDelegate (or anything after launch), not before View Controller load and execute multiple times.

Then, can you try to load these SVG files in Xcode 11 ? Xcode 11 support the SVG vector format, if this can not showing correctly in Xcode, it can not showing correctly in iOS as well. The iOS 13 system support for SVG is not always 100% compatbile for W3C SVG standard, which is a subset.

See more: Creating Custom Symbol Images for Your App

dreampiggy commented 4 years ago

From backend I got coloured images but when i shows in my code in is showing black and white. How I resolved this issue also.

Sorry, I didn't catch with this description at the above comment.

iOS UIImageView can render symbol as vector image (template), which have a Tint Color. Can be used to render the desired color. The SVG is one type of symbol image, so it also follow that design (allows you to override the color)

Which means, if you need to render SVG, you'd better configurate your UIImageView/UIImage to use the original image. Maybe I need to update some code about this framework ?

UIImage *originalImage;
UIImage *image = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
imageView.image = image;

// Or
UIImageView.tintColor = UIColor.clearColor;

See more here: Configuring and Displaying Symbol Images in Your UI

dreampiggy commented 4 years ago

Can you upload those SVG have rendering issue here, to let me test it on our demo project ?

ablyBikramjeet commented 4 years ago

Hello @dreampiggy ,

Thanks a lot for your response.

Here, am sending you .svg images URL so you can used this in your demo project.

1) http://test.yoyumm.4livedemo.com/image/cuisines/3/400/400 2) http://test.yoyumm.4livedemo.com/image/cuisines/2/400/400

Please let me know. What is your feedback on this.

Waiting for your positive response.

Thanks & Best Regards,

dreampiggy commented 4 years ago

Works on Demo:

image

ablyBikramjeet commented 4 years ago

Can you tell me the steps how you can doing this.

dreampiggy commented 4 years ago

One silly question : Are you using SVGKit (which this coder v0.1-0.3 based on, now deprecated) ? It moved to another repo, fire issue there SDWebImageSVGKitPlugin.


But actually, for any Render issue related to SVGKit, we can not help. Because they're not active developed, and no one contribute code there. We have no knowledge to modify that third party library to figure out the SVG implementation issues.

dreampiggy commented 4 years ago

Can you tell me the steps how you can doing this.

Just using the code in the demo project. Like this:

NSURL *svgURL = [NSURL URLWithString:@"http://test.yoyumm.4livedemo.com/image/cuisines/3/400/400"];
UIImageView *imageView1 = [[UIImageView alloc] init];
imageView1.frame = CGRectMake(0, 0, screenSize.width, screenSize.height / 2);
imageView1.contentMode = UIViewContentModeScaleAspectFit;
[imageView1 sd_setImageWithURL:svgURL];
ablyBikramjeet commented 4 years ago

@dreampiggy Can you tell which pod i need to install. It's good if you can send me demo project.

dreampiggy commented 4 years ago

....This GitHub repo itself? I can not get the point. This repo is what we called SVG plugin 😅

https://github.com/SDWebImage/SDWebImageSVGCoder.git

ablyBikramjeet commented 4 years ago

Wait please let me know which pod file i need to install in my project.

pod 'SDWebImageSVGCoder' pod 'SDWebImageSVGKitPlugin'

ablyBikramjeet commented 4 years ago

@dreampiggy I have used below step according to your suggestion but not able to show .svg image.

Step 1. I have created project in Objective C. Step 2. I have installed below mentioned pods :- pod 'SDWebImageSVGCoder' pod 'SDWebImageSVGKitPlugin Step 2. I have include #import <SDWebImageSVGCoder/SDWebImageSVGCoder.h> and this code in App Delegate File. SDImageSVGCoder *SVGCoder = [SDImageSVGCoder sharedCoder]; [[SDImageCodersManager sharedManager] addCoder:SVGCoder];

Step3. According your last message I have done below Code in View Controller. NSURL svgURL = [NSURL URLWithString:@"http://test.yoyumm.4livedemo.com/image/cuisines/3/400/400"]; UIImageView imageView1 = [[UIImageView alloc] init]; imageView1.frame = CGRectMake(100.0, 200.0, 200.0, 200.0); imageView1.contentMode = UIViewContentModeScaleAspectFit; [imageView1 sd_setImageWithURL:svgURL]; [imageView1 setBackgroundColor:UIColor.redColor]; [self.view addSubview:imageView1]; and Got this output -

Simulator Screen Shot - iPhone 11 Pro Max - 2019-11-27 at 13 56 00

Please help me...

dreampiggy commented 4 years ago

http

Enable the App Transport Security -> Allow arbitrary load in Info.plist

ablyBikramjeet commented 4 years ago

@dreampiggy . Thanks a lot for your response and am able to do this in demo project with Objective-C and Swift also but am unable to do this my actually project can you tell me any solution for this.

dreampiggy commented 4 years ago

@dreampiggy . Thanks a lot for your response and am able to do this in demo project with Objective-C and Swift also but am unable to do this my actually project can you tell me any solution for this.

Emm. Maybe it's about something your real project's ImageView configuration ? Or you test device's system ?

  1. This plugin support iOS 13+only (SVGKit support iOS 8+).
  2. You should register the coder plugins, using debugger to check whether SDImageCodersManager.sharedManager.coders array contains this SVG Coder
  3. Check the network issue, does the SVG image data downloaded success ?
  4. Set a break point in our code, -[SDImageSVGCoder decodeImageWithData:options:], see result whether this is get called
ablyBikramjeet commented 4 years ago

Sure @dreampiggy . Thanks a lot for your support...

dreampiggy commented 4 years ago

This plugin is actually backward-deployable. If you need to support both iOS 12/13, you need to use these two plugins at the same time.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    if #available(iOS 13, *) {
        SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared)
    } else {
        SDImageCodersManager.shared.addCoder(SDImageSVGKitCoder.shared)
    }
    return true
}