WKWebView adding cookie does not work with iOS 18 beta

If you create a cookie and add to the WKWebViewConfiguration the completionHandler returns 'Cookies synced' suggesting cookie was added with success. However, upon inspection of app in Safari the cookie is not there. This is broken in iOS 18 beta and works in previous versions without issue. Did Apple change the WKWebView API and break this feature?

code snippet: NSDictionary* settings = self.commandDelegate.settings;

WKWebViewConfiguration* configuration = [self createConfigurationFromSettings:settings]; configuration.userContentController = userContentController;

NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary]; [cookieProperties setObject:@"foo" forKey:NSHTTPCookieName]; [cookieProperties setObject:@"bar" forKey:NSHTTPCookieValue]; [cookieProperties setObject:@"mydomain.com" forKey:NSHTTPCookieDomain]; [cookieProperties setObject:@"mydomain.com" forKey:NSHTTPCookieOriginURL]; [cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];

NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties]; [configuration.websiteDataStore.httpCookieStore setCookie:cookie completionHandler:^{NSLog(@"Cookies synced");}];

WKWebView* wkWebView = [[WKWebView alloc] initWithFrame:self.engineWebView.frame configuration:configuration];

I also want to add there is an error in the Xcode console on startup of app:

Could not create a sandbox extension for '/var/containers/Bundle/Application/.....

Both build settings Use Script Sandboxing and Enable App Sandbox are set to NO. Could be that whatever is causing this error is preventing writing the cookies?

After further debugging this seems related to iOS 18 and Safari not able to read the cookies. We still have no resolution.

Issue documented in FB14862013

I also encountered a similar problem in the official version of iOS 18, the manifestation is that the document.cookie can't get the cookie set by the webview, but the cookie of the html request header has these cookies, is there a solution?

Could be related to this WebKit bug involving SameSite cookie policies: https://bugs.webkit.org/show_bug.cgi?id=279153

Is there any solution yet for this issue, i am facing issue in iOS 18. Tried 18.1 beta still same issue (17 works fine). If any solution could some one provide the solution here ? ty

Is the cookie not there, or is it there but with the wrong SameSite value? It seems in iOS18, the default SameSite value is now Lax instead of None if the server doesn't set it. I opened another forum post about it here https://developer.apple.com/forums/thread/765199 and contacted Apple support. Hoping Apple will have a workaround, as I cannot change what the server does (Salesforce in my case).

Ty, It works. By changing the document.cookie = xx=${xx}; path=/; expires=weekday, xx jan xxxx xx:xx:xx GMT; Domain=example.com; Secure; SameSite=None ;.

WKWebView adding cookie does not work with iOS 18 beta
 
 
Q