Open SeRgI1982 opened 4 years ago
Thanks for the feedback.
Next time consider attaching a sample project showing your problem.
Reviewing the API, it appears WKHttpCookieStore.AddObserver sets up use of a IWKHttpCookieStoreObserver. Have you tried using that?
It is a part of my company project, so I couldn't give you a real sample. I will try to prepare sample today evening.
About your question, yes I did exactly like you suggested. I have created this CookieStoreObserver and added an instance of this object to WKWebsiteDataStore.DefaultDataStore.HttpCookiesStore by AddObserver method. I know that generated cookie is added to this cookies store because we used it to check it if we are authenticated in SharePoint service.
Currently, it is much more like pooling approach - check if in cookie store there is a cookie which has in his property Domain a proper server name (NSHttpCookie.Domain).
I would like to avoid pooling approach and raise an event when proper cookie appears in cookie store.
Take a look on class CookieStore (XFMacSample.macOS)
One time, when I used System.Net.Cookie as a parameter for NSHttpCookie it started to work but I didn't change nothing and when I run app once again, it stopped working. Of course in this sample, I add cookie manually.
In our production app, we use WebView (WKWebView under the hood on macOS side) where we navigate to standard Microsoft login page to login to the SharePoint. As I described above, we know that successful login creates cookie and adds to WKHttpCookieStore because we check this cookie storage in a loop. We would like to move responsibility about appearing a new cookie in WKHttpCookieStore to our class CookieStore to have a chance remove this approach with loop. When observer do his job properly, it shouldn't be a problem.
Sorry for the late reply, we've been busy :smile:
Your sample works for me if I store the CookieStoreObserver
instance in a field:
CookieStoreObserver observer;
public CookieStore ()
{
observer = new CookieStoreObserver ();
observer.CookiesDidChanged += OnCookiesDidChanged;
WKWebsiteDataStore.DefaultDataStore.HttpCookieStore.AddObserver (observer);
}
then I get a dialog saying a cookie was added.
Apple's documentation about adding the observer for the event says: "The cookie store doesn’t maintain a strong reference to the object you specify."
Admittedly this is not something C# developers should have to think about, but I'm not sure we can change the API in any case. However, we can (and should) reflect this in the documentation, so I'm keeping this open as a documentation issue.
Hi,
I know that there is an interface IWKHttpCookieStoreObserver but how to use it ? I have implemented in that way:
and added to
but it is never called. I couldn't find any samples in the internet, so this place is my last chance.