Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
- (void)initWebView
// add session cookie to ajax calls
WKUserContentController* userContentController =;
WKUserScript * cookieScript =
[[WKUserScript alloc]
initWithSource: [[User sharedInstance] getJavscriptCookieString]
injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO];
[userContentController addUserScript:cookieScript];
WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] init];
webViewConfiguration.userContentController = userContentController;
webViewConfiguration.preferences.javaScriptCanOpenWindowsAutomatically = true;
_wk = [[WKWebView alloc] initWithFrame:self.view.frame configuration:webViewConfiguration];
-(NSString*) getJavscriptCookieString {
return [NSString stringWithFormat: @"document.cookie = '%@=%@'", [self getSessionName], [self getSessionValue]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.