Sdwebimage: Image should continue downloading when internet is back.

Created on 9 Aug 2018  路  6Comments  路  Source: SDWebImage/SDWebImage

New Issue Checklist

Issue Info

Info | Value |
-------------------------|-------------------------------------|
Platform Name | e.g. ios
Platform Version | e.g. 11.0
SDWebImage Version | e.g. 4.2.0
Integration Method | cocoapods
Xcode Version | e.g. Xcode 9
Repro rate | e.g. all the time (100%)
Repro with our demo prj | No, my own project.

Issue Description and Steps

I really like library and everything is working fine for me. But now i am coming a doubt when during download image and suddenly internet has been disconnected and image is not display. What i want is when internet is back the image should continue downloading from where it stopped.
What i have tried i implement options: [.progressiveDownload, .retryFailed, .continueInBackground]. I think retryFailed will continue to download when internet is back, but it doesn't. Any solution for this?

I have another doubt. For example, image has completely downloaded in view named A, and when i present another view like named B i want to get previous image in view A to display in view named B.
What i tried is that : for view A i implemented options: [.progressiveDownload, .retryFailed, .continueInBackground] and in view named B i implemented options: [ .fromCacheOnly , .retryFailed, .continueInBackground]. After, i implemented this sometime it works but it doesn't. It doesn't is that when app is killed view A is display image from its cache but when i present view B suddenly image in view named B just display placeholder image only.
The main reason that i want this feature because for example, in view A image has been finished downloaded and when user click on view named B it should display previous image from view named A because if suddenly internet has been disconnected in view named B then still user could see their image which load from view named A.

Thank for your help.

usage

Most helpful comment

By default, SDWebImage use raw NSURLSession and NSURLSessionDataTask for image data download. Some of the network related behavior can be controled by NSURLSessionConfiguration.

From iOS 11, you can try to use waitsforconnectivity, to wait for connection ability when the network disconnect temporarily.

To change the default configuration, in 4.x you can use createNewSessionWithConfiguration:. In 5.x you should configue the correct sessionConfiguration in SDWebImageDownloaderConfig.

Addition, some of options combination from your describe will not work. For example, if you provide .fromCacheOnly, which means we forbid the network request, so you don't need to pass .retryFailed, . continueInBackground.

All 6 comments

By default, SDWebImage use raw NSURLSession and NSURLSessionDataTask for image data download. Some of the network related behavior can be controled by NSURLSessionConfiguration.

From iOS 11, you can try to use waitsforconnectivity, to wait for connection ability when the network disconnect temporarily.

To change the default configuration, in 4.x you can use createNewSessionWithConfiguration:. In 5.x you should configue the correct sessionConfiguration in SDWebImageDownloaderConfig.

Addition, some of options combination from your describe will not work. For example, if you provide .fromCacheOnly, which means we forbid the network request, so you don't need to pass .retryFailed, . continueInBackground.

Thank for your reply!

If you don't mind, could you share me a sample code with createNewSessionWithConfiguration. Because i am quite familiar with that part.

Yes, i will not provide .retryFailed and .continueInBackground when i use .fromCacheOnly

Thank you.

@SamboVisal if you are using the 4.x versions of SDWebImage, then you would need to call this before anything - when the app starts for example

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
// do change the configuration as you want.
configuration.waitsForConnectivity = YES;
[[SDWebImageDownloader sharedDownloader] createNewSessionWithConfiguration:configuration];

Thank you.
waitsForConnectivity is available of iOS 11 only.
What about iOS below 11 like iOS 10 or something. What should i do sir?

Since we don't have this feature and neither does NSURLSession before iOS 11, you need to built it on your own: I would try using Reachability, mark the images not downloaded (in an array of urls for example) and just retry when the connection is back on. Or even don't start downloading if there is no connection.

Thank you for your explanation. I appreciate it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cyanzhong picture cyanzhong  路  5Comments

halilyuce picture halilyuce  路  4Comments

floprr picture floprr  路  4Comments

Ricardo1980 picture Ricardo1980  路  6Comments

ku8ar picture ku8ar  路  4Comments