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 = "https://Bibbr.kenny-it.nl";

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

    public override void ViewDidLoad()
    {
        base.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(".Bibbr.kenny-it.nl"));
        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:// Bibbr.kenny-it.nl");

        NSHttpCookieStorage.SharedStorage.SetCookie(myCookie); 

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

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

    [Export("webView:didFinishNavigation:")]
    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.