Skip to content

Instantly share code, notes, and snippets.

@fcaldarelli
Created May 14, 2019 09:50
Show Gist options
  • Save fcaldarelli/fd107097387855ee707885ac38e7d1d3 to your computer and use it in GitHub Desktop.
Save fcaldarelli/fd107097387855ee707885ac38e7d1d3 to your computer and use it in GitHub Desktop.
- (void)initWebView
{
// add session cookie to ajax calls
WKUserContentController* userContentController =
WKUserContentController.new;
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