Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress on new sites (like airbnb tablet site) #35

Open
raver99 opened this issue Dec 13, 2014 · 3 comments
Open

Progress on new sites (like airbnb tablet site) #35

raver99 opened this issue Dec 13, 2014 · 3 comments

Comments

@raver99
Copy link

raver99 commented Dec 13, 2014

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.

@raver99 raver99 changed the title Progress on new site Progress on new sites (like airbnb tablet site) Dec 13, 2014
@raver99
Copy link
Author

raver99 commented Dec 15, 2014

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

@lukas2
Copy link

lukas2 commented May 21, 2015

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.

@lukas2
Copy link

lukas2 commented Mar 22, 2016

Here is a pull request for a fix: #58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants