Skip to content

Commit 78da9cb

Browse files
committed
Added better connection dropping recovery handling.
1 parent 0f8f393 commit 78da9cb

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

TOWebViewController.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |s|
22
s.name = 'TOWebViewController'
3-
s.version = '2.0.11'
3+
s.version = '2.0.12'
44
s.license = { :type => 'MIT', :file => 'LICENSE' }
55
s.summary = 'An inline browser view controller that allows users to view and navigate web pages from within an app.'
66
s.homepage = 'https://github.com/TimOliver/TOWebViewController'
77
s.author = 'Tim Oliver'
8-
s.source = { :git => 'https://github.com/TimOliver/TOWebViewController.git', :tag => '2.0.11' }
8+
s.source = { :git => 'https://github.com/TimOliver/TOWebViewController.git', :tag => '2.0.12' }
99
s.platform = :ios, '5.0'
1010

1111
s.source_files = 'TOWebViewController/**/*.{h,m}'

TOWebViewController/TOWebViewController.m

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
747747

748748
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
749749
{
750+
self.loadingBarView.alpha = 0.0f;
750751
[self handleLoadRequestCompletion];
751752
[self refreshButtonsState];
752753
}
@@ -767,11 +768,30 @@ - (void)forwardButtonTapped:(id)sender
767768

768769
- (void)reloadStopButtonTapped:(id)sender
769770
{
770-
if (self.webView.isLoading)
771-
[self.webView stopLoading];
772-
else
773-
[self.webView reload];
771+
//regardless of reloading, or stopping, halt the webview
772+
[self.webView stopLoading];
773+
774+
if (self.webView.isLoading) {
775+
//if we were loading, hide the load bar for now
776+
self.loadingBarView.alpha = 0.0f;
777+
}
778+
else {
779+
//In certain cases, if the connection drops out preload or midload,
780+
//it nullifies webView.request, which causes [webView reload] to stop working.
781+
//This checks to see if the webView request URL is nullified, and if so, tries to load
782+
//off our stored self.url property instead
783+
NSURLRequest *request = self.webView.request;
784+
if (self.webView.request.URL.absoluteString.length == 0 && self.url)
785+
{
786+
request = [NSURLRequest requestWithURL:self.url];
787+
[self.webView loadRequest:request];
788+
}
789+
else {
790+
[self.webView reload];
791+
}
792+
}
774793

794+
//refresh the buttons
775795
[self refreshButtonsState];
776796
}
777797

@@ -1004,6 +1024,9 @@ - (void)resetLoadProgress
10041024

10051025
- (void)startLoadProgress
10061026
{
1027+
if (self.webView.isLoading == NO)
1028+
return;
1029+
10071030
//If we haven't started loading yet, set the progress to small, but visible value
10081031
if (_loadingProgressState.loadingProgress < kInitialProgressValue)
10091032
{
@@ -1051,9 +1074,6 @@ - (void)incrementLoadProgress
10511074

10521075
- (void)finishLoadProgress
10531076
{
1054-
//hide the activity indicator in the status bar
1055-
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
1056-
10571077
//reset the load progress
10581078
[self refreshButtonsState];
10591079
[self setLoadingProgress:1.0f];
@@ -1152,6 +1172,15 @@ - (void)refreshButtonsState
11521172
[self.forwardButton setEnabled:YES];
11531173
else
11541174
[self.forwardButton setEnabled:NO];
1175+
1176+
if (self.webView.isLoading) {
1177+
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
1178+
[self.reloadStopButton setImage:self.stopIcon forState:UIControlStateNormal];
1179+
}
1180+
else {
1181+
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
1182+
[self.reloadStopButton setImage:self.reloadIcon forState:UIControlStateNormal];
1183+
}
11551184
}
11561185

11571186
#pragma mark -

0 commit comments

Comments
 (0)