Skip to content

Commit

Permalink
fix(ios): cookie support for ios while using wkwebview (#10786)
Browse files Browse the repository at this point in the history
Fixes TIMOB-26903
  • Loading branch information
vijaysingh-axway authored and sgtcoolguy committed Apr 8, 2019
1 parent d1f8404 commit ded78d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions iphone/Classes/TiUIWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@ - (void)loadRequestWithURL:(NSURL *)url
[[self webView] setCustomUserAgent:userAgent];
}

if (![TiUtils isIOSVersionOrGreater:@"11.0"]) {
[self addCookieHeaderForRequest:request];
}
[self addCookieHeaderForRequest:request];

[[self webView] loadRequest:request];
}
Expand Down Expand Up @@ -617,13 +615,16 @@ - (void)_setKeyboardDisplayRequiresUserAction:(BOOL)value
- (void)addCookieHeaderForRequest:(NSMutableURLRequest *)request
{
/*
To support cookie for iOS <11
To support cookie
https://stackoverflow.com/questions/26573137
https://github.com/haifengkao/YWebView
*/

NSString *validDomain = request.URL.host;

if (validDomain.length <= 0) {
return;
}
if (!_tiCookieHandlerAdded) {
_tiCookieHandlerAdded = YES;
WKUserContentController *controller = [[[self webView] configuration] userContentController];
Expand Down Expand Up @@ -770,7 +771,7 @@ - (void)userContentController:(WKUserContentController *)userContentController d
}
}

if (![TiUtils isIOSVersionOrGreater:@"11.0"] && [message.name isEqualToString:@"_Ti_Cookie_"]) {
if ([message.name isEqualToString:@"_Ti_Cookie_"]) {
NSArray<NSString *> *cookies = [message.body componentsSeparatedByString:@"; "];
for (NSString *cookie in cookies) {
// Get this cookie's name and value
Expand Down
8 changes: 8 additions & 0 deletions iphone/Classes/TiUIWebViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,14 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N

#pragma mark Cookies

// This whole cookie code is not getting used. Reason is -
// 1. If we use this, parity can not be managed for cookies
// 2. WKHTTPCookieStore, which manages cookie in WKWebView, is supported in iOS 11+
// 3. We are using following to implement cookies-
// https://stackoverflow.com/questions/26573137
// https://github.com/haifengkao/YWebView
// TO DO: If we can make parity using WKHTTPCookieStore, we should start using WKHTTPCookieStore APIs

- (id<TiEvaluator>)evaluationContext
{
id<TiEvaluator> context = [self executionContext];
Expand Down

0 comments on commit ded78d1

Please sign in to comment.