我想保护 iPhone 上的 cache.db 文件。现在,当我安装我的应用程序并将 iPhone 连接到我的 Mac 时,我能够在应用程序文件结构中看到 cache.db 文件,并且我能够读取基本上包含请求的文件内容和回应。我将 NoCatch 应用于 HTTP 客户端对象。但不是没有区别。
HttpClientObj.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue
{
NoCache = true
};
最佳答案
翻译 the solution here with SWIFT进入 C#:
防止请求和参数写入 Cache.db
iOS
如果您使用NSUrlSession
:
var configuration = NSUrlSessionConfiguration.DefaultSessionConfiguration;
configuration.URLCache = new NSUrlCache(0,0,"");
NSUrlSession seeion = NSUrlSession.FromConfiguration(configuration);
或者设置在全局NSUrlCache
级别:
NSUrlCache.SharedCache = new NSUrlCache(0,0,"");
更新:
您可以在创建HttpClient
时使用 native 处理程序:
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
}
请记住添加对 Xamarin.iOS.dll
和 Mono.Android.dll
的引用。
关于ios - 如何在 Xamarin.iOS 中保护 cache.db 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58870923/