首页 > 解决方案 > Xamarin.iOS 等效于 Xamarin.Android 的 CookieManager.Instance

问题描述

我正在我的 Xamarin Forms 应用程序中使用 Cookie。

在某些时候,我需要将存储的 Cookie 作为字符串获取。

在 Android 中,我可以将CookieManager.Instance.GetCookie(url);其解析为返回所有 Cookie 的字符串,用 ; 分隔。

我正在寻找 Xamarin.iOS 的等价物,因为我正在开发跨平台应用程序。

期待您的回答。

标签: iosxamarincookiesxamarin.formsxamarin.ios

解决方案


在 iOS 中,如果您使用 NSUrlSession,您的 cookie 会自动与 UIWebView/WKWebView 和 NSUrlSession 共享。

要访问 Cookie 容器,您只需要使用DependencyServiceCustom Renderer进行调用。

NSHttpCookieStorage shareStore = NSHttpCookieStorage.SharedStorage;
var cookies = shareStore.CookiesForUrl(url);

推荐阅读