Forum Xamarin Xamarin.iOS

How do I add an IWKHttpCookieStoreObserver to a HttpCookieStore?

AustinGriggAustinGrigg USMember ✭✭

I'm trying to add an observer to an HttpCookieStore connected to a WebsiteDataStore for a WKWebView. I can't figure out how to build an observer that i can pass to AddObserver on HttpCookieStore. I'm really just trying to have a class that will have the CookiesDidChangeInCookieStore called when cookies change so I can save them, but it looks like it is implemented as an extension method in the docs.

I tried to do this:

public class CookieObserver : IWKHttpCookieStoreObserver


public static class CookieObserverExtensions
    public static async void CookiesDidChangeInCookieStore(this IWKHttpCookieStoreObserver This, WKHttpCookieStore cookieStore)
        var cookies = await cookieStore.GetAllCookiesAsync();

        Debug.WriteLine("Found " + cookies.Length + " cookies");

        foreach (var cookie in cookies)
            Debug.WriteLine(cookie.Domain + " - " + cookie.Name + ":" + cookie.Value);

But I get a the error "CookieObserver" does not implement interface member INativeObject.Handle.

What is the proper way to create and assign an observer for HttpCookieStore?


  • Hey Austin.
    Did you ever solve this?
    If so, could you please share the solution with us?

Sign In or Register to comment.