Skip to content

Commit

Permalink
fix(ios): sync wkwebview cookies in shared storage (#11567)
Browse files Browse the repository at this point in the history
Fixes TIMOB-27751
  • Loading branch information
vijaysingh-axway committed Mar 27, 2020
1 parent ab3d8c6 commit aab53e7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions iphone/Classes/TiUIWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ - (NSURL *)fileURLToAppURL:(NSURL *)url_
if ([path hasPrefix:@"/"]) {
path = [path substringFromIndex:1];
}
return [NSURL URLWithString:[[NSString stringWithFormat:@"app://%@/%@", TI_APPLICATION_ID, path] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
return [NSURL URLWithString:[[NSString stringWithFormat:@"app://%@/%@", TI_APPLICATION_ID, path] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]];
}

+ (BOOL)isLocalURL:(NSURL *)url
Expand Down Expand Up @@ -887,6 +887,20 @@ - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat
[self _cleanupLoadingIndicator];
[(TiUIWebViewProxy *)[self proxy] refreshHTMLContent];

if ([TiUtils isIOSVersionOrGreater:@"11.0"]) {
// TO DO: Once TIMOB-26915 done, remove this
__block BOOL finishedEvaluation = NO;
[_webView.configuration.websiteDataStore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
for (NSHTTPCookie *cookie in cookies) {
[NSHTTPCookieStorage.sharedHTTPCookieStorage setCookie:cookie];
}
finishedEvaluation = YES;
}];
while (!finishedEvaluation) {
[NSRunLoop.currentRunLoop runMode:NSDefaultRunLoopMode beforeDate:NSDate.distantFuture];
}
}

if ([[self proxy] _hasListeners:@"load"]) {
[[self proxy] fireEvent:@"load" withObject:@{ @"url" : webView.URL.absoluteString, @"title" : webView.title }];
}
Expand Down Expand Up @@ -1053,13 +1067,13 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WK
DebugLog(@"[WARN] In iOS, please use the \"handleurl\" event together with \"allowedURLSchemes\" in Ti.UI.WebView.");
DebugLog(@"[WARN] In iOS, it returns both the \"url\" and \"handler\" property to open a URL and invoke the decision-handler.");

[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
[UIApplication.sharedApplication openURL:navigationAction.request.URL options:@{} completionHandler:nil];
decisionHandler(WKNavigationActionPolicyCancel);
}
}
} else if (!([scheme hasPrefix:@"http"] || [scheme isEqualToString:@"ftp"] || [scheme isEqualToString:@"file"] || [scheme isEqualToString:@"app"]) && [[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
// Support tel: protocol
[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
[UIApplication.sharedApplication openURL:navigationAction.request.URL options:@{} completionHandler:nil];
decisionHandler(WKNavigationActionPolicyCancel);
} else {
BOOL valid = !ignoreNextRequest;
Expand Down

0 comments on commit aab53e7

Please sign in to comment.