Search code examples
ioscookiesuiwebviewmobile-safariwkwebview

Writing a cookie inside WKUIWebView visible from Mobile Safari


I'm trying to load a web Url from inside my app and I need to set a cookie. At the moment I'm using:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:_myURL]];

but this approach results in my app switching to Mobile Safari which is quite ugly as the user loses the focus on my app. Loading the web page inside the new WKUIWebView (and using NSHttpCookieStorage) is not an option as apparently those cookie would be sandboxed. Is there any other way I can create a cookie which is visible from Mobile Safari?


Solution

  • As of iOS9 you can use the SFSafariViewController which does share cookies with Safari mobile. You can use this in conjunction with custom URL schemes or universal links to "communicate" between them.