Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

WKWebView doesn't send setCookie???

SynteXSynteX NLMember ✭✭

Hey all,

(You can see my code below)
I'm trying to set a cookie so my website knows I am using the app.
The cookie is set if i read the cookies from the site it says its there.

BUT. My website doesn't see the cookie? So i assume it's not send by the WKWebViewer.
What do I do wrong? Or what do I miss?

`public partial class ViewController : UIViewController, IWKNavigationDelegate
private string url = "";

    protected ViewController(IntPtr handle) : base(handle)
        // Note: this .ctor should not contain any initialization logic.

    public override void ViewDidLoad()
        // Perform any additional setup after loading the view, typically from a nib.

        // Set cookie
        /*var cookieDict = new NSMutableDictionary();
        cookieDict.Add(NSHttpCookie.KeyOriginUrl, new NSString(""));
        cookieDict.Add(NSHttpCookie.KeyName, new NSString("using_app"));
        cookieDict.Add(NSHttpCookie.KeyValue, new NSString("1"));
        cookieDict.Add(NSHttpCookie.KeyPath, new NSString("/"));*/

        var myCookie = new NSHttpCookie("using_app", "1", "/", "https://");


        // Load page
        var request = new NSUrlRequest(new NSUrl(url));
        webView.NavigationDelegate = this;

    public override void DidReceiveMemoryWarning()
        // Release any cached data, images, etc that aren't in use.

    public void DidFinishNavigation(WKWebView wv, WKNavigation navigation)
        foreach(NSHttpCookie cookie in NSHttpCookieStorage.SharedStorage.CookiesForUrl(wv.Url))
            Console.WriteLine(cookie.Name + " -" + cookie.Domain + " - " + cookie.Path);

        /*var alert = UIAlertController.Create("Test", cookies, UIAlertControllerStyle.Alert);

        alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

        PresentViewController(alert, true, null);*/
Sign In or Register to comment.