evermeer / EVURLCache

a NSURLCache subclass for handling all web requests that use NSURLRequest
Other
297 stars 48 forks source link

Without network nothing is loaded #12

Closed Greg767 closed 8 years ago

Greg767 commented 8 years ago

Hi,

Thanks a lot for this library! I just tried the demo app without any modifications on a 9.2 iPhone 5s and without the wifi connection nothing is loaded. Then I turn on the wifi, your website is loaded I navigate to a submenu, I quit, I come back with wifi OFF and nothing loads upon opening the app. I get a white page. Thanks!

evermeer commented 8 years ago

I see that in my latest change where i changed from just writing the content to using NSKeyedArchiver to save the entire request does not work with my own site. I used the NSKeyedArchiver so that there would be an identical copy of the complete response. This was needed for the alternate url that you see in the ViewController.

In the code below you can see where it goes wrong. When using just the return response then the game from the alternate url in the ViewController will work. When using the return above that where it's build up from scratch my own site will work.

    if let response = NSKeyedUnarchiver.unarchiveObjectWithFile(storagePath) as? NSCachedURLResponse {
        EVURLCache.debugLog("Returning cached data from \(storagePath)");

        let r = NSURLResponse(URL: response.response.URL!, MIMEType: response.response.MIMEType, expectedContentLength: response.data.length, textEncodingName: response.response.textEncodingName)
        //return NSCachedURLResponse(response: r, data: response.data, userInfo: response.userInfo, storagePolicy: .Allowed)

        return response
    }

So I have to find out what the differences are between these 2... I will do some more investigation..

Greg767 commented 8 years ago

Thanks a lot for looking into it!

evermeer commented 8 years ago

I have pushed a new version where it is working again. I added an option to the library where you could choose the way how to restore the cache (direct from NSArchiver or recreating the response object) The default option should be good enough for more than 9 out of 10 websites.

Instead of an option I would still like to find out how to automatically do the right thing. So I will keep this issue open and label it improvement so that I can pick this up later (for now I have other priorities)

Greg767 commented 8 years ago

Cool! Thanks a lot for the quick fix!