Forum Xamarin Xamarin.iOS

Set cookies in WKWebView

Hello good day.
I have an app that opens a website with credentials of a particular user within a WkWebView. When the user wants to download a file, it is already PDF, Word, Excel, TXT. WkWebView does not set the cookies that contain the credentials of the user logged on the web.
Is there a way to set cookies so that pressing the download button on my website will download the file to my cell phone?

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    We need to manually add cookies like what this thread said:
    https://stackoverflow.com/a/26577303/8354952
    It was a swift answer. We could convert it to Xamarin like:

    NSDictionary properties = NSDictionary.FromObjectsAndKeys(new NSString[] { new NSString("domain.com"), new NSString("/"), new NSString("key"), new NSString("value") },
                                                                new NSString[] { NSHttpCookie.KeyOriginUrl, NSHttpCookie.KeyPath, NSHttpCookie.KeyName, NSHttpCookie.KeyValue});
    var cookie = new NSHttpCookie(properties);
    await webView.Configuration.WebsiteDataStore.HttpCookieStore.SetCookieAsync(cookie);
    
  • Matias_2209Matias_2209 Member

    Hello LandLu.
    I am going to prove with what you have told me and I am writing to see how the change went.
    For the moment thank you very much for the contribution.

  • LandLuLandLu Member, Xamarin Team Xamurai

    I'm willing to hear your feedback.

Sign In or Register to comment.