Hello,
Welcome to our Microsoft Q&A platform!
Hi, David. How did you remove the cookies in your project? To remove the cookies in Xamarin.Forms, please achieve the function on each platform. You could call the function code in the shared project using DependencySerive. Here is the related code, you could refer to:
1.Create an interface for the native platform functionality in the shared project.
namespace TestApplication
{
public interface IClearCookiesInterface
{
void ClearAllCookies();
}
}
2.Implement the interface in the required platform projects and register the platform implementations.
//android
[assembly: Xamarin.Forms.Dependency(typeof(DroidImplementation))]
namespace TestApplication.Droid
{
public class DroidImplementation : IClearCookiesInterface
{
public void ClearAllCookies()
{
var cookieManager = CookieManager.Instance;
cookieManager.RemoveAllCookie();
}
}
}
//ios
[assembly: Dependency(typeof(IOSImplementation))]
namespace TestApplication.iOS
{
public class IOSImplementation : IClearCookiesInterface
{
public void ClearAllCookies()
{
NSHttpCookieStorage CookieStorage = NSHttpCookieStorage.SharedStorage;
foreach (var cookie in CookieStorage.Cookies)
{
CookieStorage.DeleteCookie(cookie);
}
}
}
}
3.Invoke the function code in the shared project.
DependencyService.Get<IClearCookiesInterface>().ClearAllCookies();
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.