I understand that with iOS9 you can read cookies using SFSafariViewController.
If I set a cookie on my page in JS using the following:
var dd = new Date(Date.now() + 1000 * 60 * 60 * 24).toGMTString(); var expires = "expires="+ dd; document.cookie = "mycookie=cookievalue; " + expires + " domain=.mydomain.co.uk ; path=/ ";
If I do this:
- (void)safariViewController:(SFSafariViewController *)controller didCompleteInitialLoad:(BOOL)didLoadSuccessfully { NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSArray *cookiesArray = [storage cookies]; }
cookieArray is always empty.
If I use the traditional UIWebView interface
-(void)webViewDidFinishLoad:(UIWebView *)webView { NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSArray *cookiesArray = [storage cookies]; }
I get the cookie I was expecting.
Any ideas what I can do wrong?
source share