0

I'd like to secure cache.db file on iPhone. Now when I install my App and connect the iPhone to my Mac, I'm able to see cache.db file in the apps file structure and I'm able to read the file contents that basically contains requests and responses. I Applied NoCatch with HTTP client object. But not it makes no difference.

HttpClientObj.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue 
                                                       { 
                                                           NoCache = true 
                                                       };
Paul Kertscher
  • 9,416
  • 5
  • 32
  • 57
Abhishek Maurya
  • 163
  • 1
  • 9

2 Answers2

1

Translate the solution here with SWIFT into c#:

To prevent request and parameters being written to the Cache.db iOS

If you are using NSUrlSession :

    var configuration = NSUrlSessionConfiguration.DefaultSessionConfiguration;
    configuration.URLCache = new NSUrlCache(0,0,"");

    NSUrlSession seeion = NSUrlSession.FromConfiguration(configuration);

Or set at a global NSUrlCache level:

    NSUrlCache.SharedCache = new NSUrlCache(0,0,"");

Update:

You can use native handler when creating HttpClient:

    public MainPage()
    {
        InitializeComponent();

        HttpClient httpClient;

        if (Device.RuntimePlatform == Device.iOS)
        {
            var configuration = NSUrlSessionConfiguration.DefaultSessionConfiguration;
            configuration.URLCache = new NSUrlCache(0, 0, "");

            NSUrlSessionHandler handler = new NSUrlSessionHandler(configuration);
            httpClient = new HttpClient(handler);
        }else if (Device.RuntimePlatform == Device.Android)
        {
            AndroidClientHandler handler = new AndroidClientHandler();
            httpClient = new HttpClient(handler);
        }

        //...your request
    }

Remember to Add reference to Xamarin.iOS.dll and Mono.Android.dll.

nevermore
  • 15,432
  • 1
  • 12
  • 30
-1

CacheControl HeaderValue works me

System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient();
 httpClient.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true };

Documentation

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
Gouraw
  • 49
  • 5