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

Bugfix : add fix in finish: and shouldStart:'s method #82

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions NJKWebViewProgress/NJKWebViewProgress.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)

BOOL isFragmentJump = NO;
if (request.URL.fragment) {
NSString *nonFragmentURL = [request.URL.absoluteString stringByReplacingOccurrencesOfString:[@"#" stringByAppendingString:request.URL.fragment] withString:@""];
isFragmentJump = [nonFragmentURL isEqualToString:webView.request.URL.absoluteString];
isFragmentJump = [[self nonFragmentURL:request.URL] isEqual:[self nonFragmentURL:webView.request.URL]];
}

BOOL isTopLevelNavigation = [request.mainDocumentURL isEqual:request.URL];
Expand Down Expand Up @@ -136,7 +135,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
[webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS];
}

BOOL isNotRedirect = _currentURL && [_currentURL isEqual:webView.request.mainDocumentURL];
BOOL isNotRedirect = [[self nonFragmentURL:_currentURL] isEqual:[self nonFragmentURL: webView.request.mainDocumentURL]];
BOOL complete = [readyState isEqualToString:@"complete"];
if (complete && isNotRedirect) {
[self completeProgress];
Expand All @@ -161,13 +160,22 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
[webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS];
}

BOOL isNotRedirect = _currentURL && [_currentURL isEqual:webView.request.mainDocumentURL];
BOOL isNotRedirect = [[self nonFragmentURL:_currentURL] isEqual:[self nonFragmentURL: webView.request.mainDocumentURL]];
BOOL complete = [readyState isEqualToString:@"complete"];
if ((complete && isNotRedirect) || error) {
[self completeProgress];
}
}

- (NSURL *)nonFragmentURL:(NSURL *)sourceUrl{
NSURL *nonFragmentUrl = sourceUrl;
if(sourceUrl && sourceUrl.fragment){
NSString *nonFragmentUrlStr = [sourceUrl.absoluteString stringByReplacingOccurrencesOfString:[@"#" stringByAppendingString:sourceUrl.fragment] withString:@""];
nonFragmentUrl = [NSURL URLWithString:nonFragmentUrlStr];
}
return nonFragmentUrl;
}

#pragma mark -
#pragma mark Method Forwarding
// for future UIWebViewDelegate impl
Expand Down