Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KFSwiftImageLoader #21

Closed
ghost opened this issue Nov 25, 2015 · 8 comments
Closed

KFSwiftImageLoader #21

ghost opened this issue Nov 25, 2015 · 8 comments
Labels

Comments

@ghost
Copy link

ghost commented Nov 25, 2015

Great tool!

Would you expect this to work with https://github.com/kiavashfaisali/KFSwiftImageLoader ?

I'm able to see other request/responses in netfox, except for those...

@kasketis
Copy link
Owner

Thanks for the info! I will check it and get back to you! :)

@kasketis
Copy link
Owner

Hi! I managed to get it work by replacing the

    internal lazy var session: NSURLSession = {
        let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
        configuration.requestCachePolicy = .ReturnCacheDataElseLoad
        configuration.URLCache = .sharedURLCache()
        return NSURLSession(configuration: configuration)
    }()

with this

    internal lazy var session: NSURLSession = {
        let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
        configuration.protocolClasses?.insert(NFXProtocol.self, atIndex: 0) //added line
        configuration.requestCachePolicy = .ReturnCacheDataElseLoad
        configuration.URLCache = .sharedURLCache()
        return NSURLSession(configuration: configuration)
    }()

in the KFImageCacheManager.swift file

Attention: You will get image log only the first time because KFSwiftImageLoader caches the images and doesn't request them again

Please verify the workaround :)

@kasketis
Copy link
Owner

Also make sure you delete the app from the device/simulator and make a Product > Clean before you rebuild

@ghost
Copy link
Author

ghost commented Nov 30, 2015

Hey Thanks! Confirmed this works in principal, though it was a little tricky coming up with a way to do it using both KF and NF as cocoa pods. Ended up exposing a way to modify the session configuration in KFSwiftImageLoader from the app which has visibility to Netfox module.

Cheers.

@kasketis
Copy link
Owner

Nice :) Could you please post your workaround?

@ghost
Copy link
Author

ghost commented Feb 24, 2016

All I did was to provide a way for an app to override the session configuration before the NSURLSession in KFImageCacheManager is initialized.

    public static var sessionConfigurationOverride: NSURLSessionConfiguration?

    lazy var session: NSURLSession = {
        if let config = sessionConfigurationOverride {
          return NSURLSession(configuration: config)
        } else {
          let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
          configuration.requestCachePolicy = .ReturnCacheDataElseLoad
          configuration.URLCache = .sharedURLCache()
          return NSURLSession(configuration: configuration)
        }
    }()

Then, upon starting the app, inject a config that puts the NFXProtocol in the middle to capture the image requests

        let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
        configuration.protocolClasses?.insert(NFXProtocol.self, atIndex: 0)
        configuration.requestCachePolicy = .ReturnCacheDataElseLoad
        configuration.URLCache = .sharedURLCache()
        KFImageCacheManager.sessionConfigurationOverride = configuration

It is a bit of a run-around, but it's working.

@Janglinator
Copy link
Contributor

PR #94 will solve issues like these

@kasketis
Copy link
Owner

Since #94 merged, I consider it as solved. Please come back with a new issue if not. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants