locked
How to disable caching in NSUrlSessionConfiguration in unified API RRS feed

  • Question

  • User14070 posted

    Hi,

    In Apple docs (https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSessionConfigurationclass/index.html#//appleref/occ/instp/NSURLSessionConfiguration/URLCache) we can pass nil to disable caching in NSUrlSessionConfiguration.

    In classic API, I can work-around by create new URLCache with IntPtr.Zero but in unified api, I can not do this way anymore. I have also tried to pass null value but it throw exception, preventing me to do that.

    How can I do that with Xamarin unified API ?

    Tuesday, February 17, 2015 4:38 PM

All replies

  • User31231 posted

    Hi @AnNgo.7471,

    It sounds like there could be an issue in the binding for the NSUrlSessionConfiguration class. Could you please file a bug on Bugzilla?

    Thanks,

    Kevin

    Tuesday, February 17, 2015 4:45 PM
  • User181 posted

    If the documentation says null is allowed but the binding throws an exception then report a bug. Those are pretty easy to fix, and they usually do it quickly (although you'll have to wait for the next release).

    In the meantime you will have to do it manually with this ugly code:

    // Somewhere in your class
    [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
    private static extern void void_objc_msgSend_int_IntPtr_Double_IntPtr_IntPtr(IntPtr receiver, IntPtr selector, int arg1, IntPtr arg2, double arg3, IntPtr arg4, IntPtr arg5);    
    
    // In lieu of sessionConfiguration.URLCache = new NSUrlCache(null);
    void_objc_msgSend_IntPtr(sessionConfiguration.Handle, Selector.GetHandle("setURLCache:"), IntPtr.Zero);
    
    Tuesday, February 17, 2015 4:53 PM
  • User14070 posted

    Thank adamkemp, that resolved my issue, the code seem ugly, but it works :-). I also submitted a bug on Bugzilla, hope they will fix it in next release.

    Thank you all for your help,

    Tuesday, February 17, 2015 8:11 PM