NJKWebViewProgress
NJKWebViewProgress copied to clipboard
Progress on new sites (like airbnb tablet site)
Hello,
I think your control is great and would love to use it but some new sites (airbnb on iPad iOS 8.0) gets stuck at 50%.
Could you please have a look, or maybe point out what goes wrong. Thanks, R.
I checked this issues running on iOS 7.1 (built with 7.1 SDK). Here it works fine so I guess something changed in 8.
I will try to figure it out myself, might take a while, but I would enormously appreciate your help. Thanks, Roland
Did you happen to find a good fix? I am about to go home, but I've stumbled over the same problem. I think the problem is here:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if ([_webViewProxyDelegate respondsToSelector:@selector(webViewDidFinishLoad:)]) {
[_webViewProxyDelegate webViewDidFinishLoad:webView];
}
_loadingCount--;
[self incrementProgress];
NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"];
BOOL interactive = [readyState isEqualToString:@"interactive"];
if (interactive) {
_interactive = YES;
NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@://%@%@'; document.body.appendChild(iframe); }, false);", webView.request.mainDocumentURL.scheme, webView.request.mainDocumentURL.host, completeRPCURLPath];
[webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS];
}
BOOL isNotRedirect = _currentURL && [_currentURL isEqual:webView.request.mainDocumentURL];
BOOL complete = [readyState isEqualToString:@"complete"];
if (complete && isNotRedirect) {
[self completeProgress];
}
}
specifically this line:
BOOL isNotRedirect = _currentURL && [_currentURL isEqual:webView.request.mainDocumentURL];
I've noticed that in my case, the URL is changed (probably by Javascript), after the hash sign. Thus isNotRedirect
was false.
I'm going home now and I don't know if this is a clean fix or even a fix, but it appears to work now for me using this code:
BOOL isNotRedirect = YES;
if (_currentURL != nil && _currentURL.fragment != nil) {
NSString *nonFragmentCurrentURL = [_currentURL.absoluteString stringByReplacingOccurrencesOfString:[@"#" stringByAppendingString:_currentURL.fragment] withString:@""];
NSString *nonFragmentMainDocumentURL = [webView.request.mainDocumentURL.absoluteString stringByReplacingOccurrencesOfString:[@"#" stringByAppendingString:webView.request.mainDocumentURL.fragment] withString:@""];
isNotRedirect = _currentURL && [nonFragmentCurrentURL isEqual:nonFragmentMainDocumentURL];
}
To detect the redirect I use the URLs without the fragment.
Here is a pull request for a fix: https://github.com/ninjinkun/NJKWebViewProgress/pull/58