From 25f8fffb226d344b5a714af1ac45cc3bcb7d3f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Radm=C3=BCller?= Date: Mon, 5 Oct 2020 16:32:29 +0200 Subject: [PATCH] feat: removed deprected UIWebView fixes #69 --- KINWebBrowser.podspec | 6 +- KINWebBrowser/KINWebBrowserViewController.h | 10 +- KINWebBrowser/KINWebBrowserViewController.m | 221 +++----------------- README.md | 6 +- 4 files changed, 39 insertions(+), 204 deletions(-) diff --git a/KINWebBrowser.podspec b/KINWebBrowser.podspec index 95d971d..745c86d 100644 --- a/KINWebBrowser.podspec +++ b/KINWebBrowser.podspec @@ -2,16 +2,16 @@ Pod::Spec.new do |s| s.name = "KINWebBrowser" - s.version = "1.3.2" + s.version = "1.3.3" s.summary = "A web browser module for your apps." s.description = <<-DESC - KINWebBrowser is a web browser module for your apps. Powered by WKWebView on iOS 8. Backwards compatible with iOS 7 using UIWebView. KINWebBrowser offers the simplest way to add a web browser to your apps. + KINWebBrowser is a web browser module for your apps. Powered by WKWebView on iOS 8. KINWebBrowser offers the simplest way to add a web browser to your apps. DESC s.homepage = "https://github.com/dfmuir/KINWebBrowser" s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "David F. Muir V" => "dfmuir@gmail.com" } - s.platform = :ios, '7.0' + s.platform = :ios, '8.0' s.source = { :git => "https://github.com/dfmuir/KINWebBrowser.git", :tag => s.version.to_s } s.source_files = 'KINWebBrowser', 'KINWebBrowser/**/*.{h,m}' s.resources = "Assets/*.png" diff --git a/KINWebBrowser/KINWebBrowserViewController.h b/KINWebBrowser/KINWebBrowserViewController.h index 64a5087..c580547 100644 --- a/KINWebBrowser/KINWebBrowserViewController.h +++ b/KINWebBrowser/KINWebBrowserViewController.h @@ -31,7 +31,6 @@ // #import -#import @class KINWebBrowserViewController; @@ -64,7 +63,7 @@ For convenience, two sets of static initializers are available. */ -@interface KINWebBrowserViewController : UIViewController +@interface KINWebBrowserViewController : UIViewController #pragma mark - Public Properties @@ -76,9 +75,8 @@ // The web views // Depending on the version of iOS, one of these will be set @property (nonatomic, strong) WKWebView *wkWebView; -@property (nonatomic, strong) UIWebView *uiWebView; -- (id)initWithConfiguration:(WKWebViewConfiguration *)configuration NS_AVAILABLE_IOS(8_0); +- (id)initWithConfiguration:(WKWebViewConfiguration *)configuration #pragma mark - Static Initializers @@ -91,7 +89,7 @@ */ + (KINWebBrowserViewController *)webBrowser; -+ (KINWebBrowserViewController *)webBrowserWithConfiguration:(WKWebViewConfiguration *)configuration NS_AVAILABLE_IOS(8_0); ++ (KINWebBrowserViewController *)webBrowserWithConfiguration:(WKWebViewConfiguration *)configuration /* Initialize a UINavigationController with a KINWebBrowserViewController for modal presentation. @@ -102,7 +100,7 @@ */ + (UINavigationController *)navigationControllerWithWebBrowser; -+ (UINavigationController *)navigationControllerWithWebBrowserWithConfiguration:(WKWebViewConfiguration *)configuration NS_AVAILABLE_IOS(8_0); ++ (UINavigationController *)navigationControllerWithWebBrowserWithConfiguration:(WKWebViewConfiguration *)configuration @property (nonatomic, strong) UIBarButtonItem *actionButton; diff --git a/KINWebBrowser/KINWebBrowserViewController.m b/KINWebBrowser/KINWebBrowserViewController.m index 5355114..21055e2 100644 --- a/KINWebBrowser/KINWebBrowserViewController.m +++ b/KINWebBrowser/KINWebBrowserViewController.m @@ -41,10 +41,7 @@ @interface KINWebBrowserViewController () @property (nonatomic, assign) BOOL previousNavigationControllerToolbarHidden, previousNavigationControllerNavigationBarHidden; @property (nonatomic, strong) UIBarButtonItem *backButton, *forwardButton, *refreshButton, *stopButton, *fixedSeparator, *flexibleSeparator; -@property (nonatomic, strong) NSTimer *fakeProgressTimer; @property (nonatomic, strong) UIPopoverController *actionPopoverController; -@property (nonatomic, assign) BOOL uiWebViewIsLoading; -@property (nonatomic, strong) NSURL *uiWebViewCurrentURL; @property (nonatomic, strong) NSURL *URLToLaunchWithPermission; @property (nonatomic, strong) UIAlertView *externalAppPermissionAlertView; @@ -91,18 +88,14 @@ - (id)init { - (id)initWithConfiguration:(WKWebViewConfiguration *)configuration { self = [super init]; if(self) { - if([WKWebView class]) { - if(configuration) { - self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration]; - } - else { - self.wkWebView = [[WKWebView alloc] init]; - } + if(configuration) { + self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration]; } else { - self.uiWebView = [[UIWebView alloc] init]; + self.wkWebView = [[WKWebView alloc] init]; } + self.actionButtonHidden = NO; self.showsURLInNavigationBar = NO; self.showsPageTitleInNavigationBar = YES; @@ -121,28 +114,16 @@ - (void)viewDidLoad { self.previousNavigationControllerToolbarHidden = self.navigationController.toolbarHidden; self.previousNavigationControllerNavigationBarHidden = self.navigationController.navigationBarHidden; - if(self.wkWebView) { - [self.wkWebView setFrame:self.view.bounds]; - [self.wkWebView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; - [self.wkWebView setNavigationDelegate:self]; - [self.wkWebView setUIDelegate:self]; - [self.wkWebView setMultipleTouchEnabled:YES]; - [self.wkWebView setAutoresizesSubviews:YES]; - [self.wkWebView.scrollView setAlwaysBounceVertical:YES]; - [self.view addSubview:self.wkWebView]; - - [self.wkWebView addObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress)) options:0 context:KINWebBrowserContext]; - } - else if(self.uiWebView) { - [self.uiWebView setFrame:self.view.bounds]; - [self.uiWebView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; - [self.uiWebView setDelegate:self]; - [self.uiWebView setMultipleTouchEnabled:YES]; - [self.uiWebView setAutoresizesSubviews:YES]; - [self.uiWebView setScalesPageToFit:YES]; - [self.uiWebView.scrollView setAlwaysBounceVertical:YES]; - [self.view addSubview:self.uiWebView]; - } + [self.wkWebView setFrame:self.view.bounds]; + [self.wkWebView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; + [self.wkWebView setNavigationDelegate:self]; + [self.wkWebView setUIDelegate:self]; + [self.wkWebView setMultipleTouchEnabled:YES]; + [self.wkWebView setAutoresizesSubviews:YES]; + [self.wkWebView.scrollView setAlwaysBounceVertical:YES]; + [self.view addSubview:self.wkWebView]; + + [self.wkWebView addObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress)) options:0 context:KINWebBrowserContext]; self.progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; @@ -169,19 +150,13 @@ - (void)viewWillDisappear:(BOOL)animated { [self.navigationController setToolbarHidden:self.previousNavigationControllerToolbarHidden animated:animated]; - [self.uiWebView setDelegate:nil]; [self.progressView removeFromSuperview]; } #pragma mark - Public Interface - (void)loadRequest:(NSURLRequest *)request { - if(self.wkWebView) { - [self.wkWebView loadRequest:request]; - } - else if(self.uiWebView) { - [self.uiWebView loadRequest:request]; - } + [self.wkWebView loadRequest:request]; } - (void)loadURL:(NSURL *)URL { @@ -194,12 +169,7 @@ - (void)loadURLString:(NSString *)URLString { } - (void)loadHTMLString:(NSString *)HTMLString { - if(self.wkWebView) { - [self.wkWebView loadHTMLString:HTMLString baseURL:nil]; - } - else if(self.uiWebView) { - [self.uiWebView loadHTMLString:HTMLString baseURL:nil]; - } + [self.wkWebView loadHTMLString:HTMLString baseURL:nil]; } - (void)setTintColor:(UIColor *)tintColor { @@ -220,61 +190,6 @@ - (void)setActionButtonHidden:(BOOL)actionButtonHidden { [self updateToolbarState]; } - -#pragma mark - UIWebViewDelegate - -- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { - if(webView == self.uiWebView) { - - if(![self externalAppRequiredToOpenURL:request.URL]) { - self.uiWebViewCurrentURL = request.URL; - self.uiWebViewIsLoading = YES; - [self updateToolbarState]; - - [self fakeProgressViewStartLoading]; - - if([self.delegate respondsToSelector:@selector(webBrowser:didStartLoadingURL:)]) { - [self.delegate webBrowser:self didStartLoadingURL:request.URL]; - } - return YES; - } - else { - [self launchExternalAppWithURL:request.URL]; - return NO; - } - } - return NO; -} - -- (void)webViewDidFinishLoad:(UIWebView *)webView { - if(webView == self.uiWebView) { - if(!self.uiWebView.isLoading) { - self.uiWebViewIsLoading = NO; - [self updateToolbarState]; - - [self fakeProgressBarStopLoading]; - } - - if([self.delegate respondsToSelector:@selector(webBrowser:didFinishLoadingURL:)]) { - [self.delegate webBrowser:self didFinishLoadingURL:self.uiWebView.request.URL]; - } - } -} - -- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { - if(webView == self.uiWebView) { - if(!self.uiWebView.isLoading) { - self.uiWebViewIsLoading = NO; - [self updateToolbarState]; - - [self fakeProgressBarStopLoading]; - } - if([self.delegate respondsToSelector:@selector(webBrowser:didFailToLoadURL:error:)]) { - [self.delegate webBrowser:self didFailToLoadURL:self.uiWebView.request.URL error:error]; - } - } -} - #pragma mark - WKNavigationDelegate - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { @@ -348,8 +263,8 @@ - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWe - (void)updateToolbarState { - BOOL canGoBack = self.wkWebView.canGoBack || self.uiWebView.canGoBack; - BOOL canGoForward = self.wkWebView.canGoForward || self.uiWebView.canGoForward; + BOOL canGoBack = self.wkWebView.canGoBack + BOOL canGoForward = self.wkWebView.canGoForward [self.backButton setEnabled:canGoBack]; [self.forwardButton setEnabled:canGoForward]; @@ -359,17 +274,11 @@ - (void)updateToolbarState { } NSArray *barButtonItems; - if(self.wkWebView.loading || self.uiWebViewIsLoading) { + if(self.wkWebView.loading) { barButtonItems = @[self.backButton, self.fixedSeparator, self.forwardButton, self.fixedSeparator, self.stopButton, self.flexibleSeparator]; if(self.showsURLInNavigationBar) { - NSString *URLString; - if(self.wkWebView) { - URLString = [self.wkWebView.URL absoluteString]; - } - else if(self.uiWebView) { - URLString = [self.uiWebViewCurrentURL absoluteString]; - } + NSString *URLString = [self.wkWebView.URL absoluteString]; URLString = [URLString stringByReplacingOccurrencesOfString:@"http://" withString:@""]; URLString = [URLString stringByReplacingOccurrencesOfString:@"https://" withString:@""]; @@ -381,12 +290,7 @@ - (void)updateToolbarState { barButtonItems = @[self.backButton, self.fixedSeparator, self.forwardButton, self.fixedSeparator, self.refreshButton, self.flexibleSeparator]; if(self.showsPageTitleInNavigationBar) { - if(self.wkWebView) { - self.navigationItem.title = self.wkWebView.title; - } - else if(self.uiWebView) { - self.navigationItem.title = [self.uiWebView stringByEvaluatingJavaScriptFromString:@"document.title"]; - } + self.navigationItem.title = self.wkWebView.title; } } @@ -430,57 +334,29 @@ - (void)doneButtonPressed:(id)sender { #pragma mark - UIBarButtonItem Target Action Methods - (void)backButtonPressed:(id)sender { - - if(self.wkWebView) { - [self.wkWebView goBack]; - } - else if(self.uiWebView) { - [self.uiWebView goBack]; - } + [self.wkWebView goBack]; [self updateToolbarState]; } - (void)forwardButtonPressed:(id)sender { - if(self.wkWebView) { - [self.wkWebView goForward]; - } - else if(self.uiWebView) { - [self.uiWebView goForward]; - } + [self.wkWebView goForward]; [self updateToolbarState]; } - (void)refreshButtonPressed:(id)sender { - if(self.wkWebView) { - [self.wkWebView stopLoading]; - [self.wkWebView reload]; - } - else if(self.uiWebView) { - [self.uiWebView stopLoading]; - [self.uiWebView reload]; - } + [self.wkWebView stopLoading]; + [self.wkWebView reload]; } - (void)stopButtonPressed:(id)sender { - if(self.wkWebView) { - [self.wkWebView stopLoading]; - } - else if(self.uiWebView) { - [self.uiWebView stopLoading]; - } + [self.wkWebView stopLoading]; } - (void)actionButtonPressed:(id)sender { NSURL *URLForActivityItem; NSString *URLTitle; - if(self.wkWebView) { - URLForActivityItem = self.wkWebView.URL; - URLTitle = self.wkWebView.title; - } - else if(self.uiWebView) { - URLForActivityItem = self.uiWebView.request.URL; - URLTitle = [self.uiWebView stringByEvaluatingJavaScriptFromString:@"document.title"]; - } + URLForActivityItem = self.wkWebView.URL; + URLTitle = self.wkWebView.title; if (URLForActivityItem) { dispatch_async(dispatch_get_main_queue(), ^{ TUSafariActivity *safariActivity = [[TUSafariActivity alloc] init]; @@ -532,43 +408,6 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N } } - -#pragma mark - Fake Progress Bar Control (UIWebView) - -- (void)fakeProgressViewStartLoading { - [self.progressView setProgress:0.0f animated:NO]; - [self.progressView setAlpha:1.0f]; - - if(!self.fakeProgressTimer) { - self.fakeProgressTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f target:self selector:@selector(fakeProgressTimerDidFire:) userInfo:nil repeats:YES]; - } -} - -- (void)fakeProgressBarStopLoading { - if(self.fakeProgressTimer) { - [self.fakeProgressTimer invalidate]; - } - - if(self.progressView) { - [self.progressView setProgress:1.0f animated:YES]; - [UIView animateWithDuration:0.3f delay:0.3f options:UIViewAnimationOptionCurveEaseOut animations:^{ - [self.progressView setAlpha:0.0f]; - } completion:^(BOOL finished) { - [self.progressView setProgress:0.0f animated:NO]; - }]; - } -} - -- (void)fakeProgressTimerDidFire:(id)sender { - CGFloat increment = 0.005/(self.progressView.progress + 0.2); - if([self.uiWebView isLoading]) { - CGFloat progress = (self.progressView.progress < 0.75f) ? self.progressView.progress + increment : self.progressView.progress + 0.0005; - if(self.progressView.progress < 0.95) { - [self.progressView setProgress:progress animated:YES]; - } - } -} - #pragma mark - External App Support - (BOOL)externalAppRequiredToOpenURL:(NSURL *)URL { @@ -616,9 +455,7 @@ - (BOOL)shouldAutorotate { #pragma mark - Dealloc -- (void)dealloc { - [self.uiWebView setDelegate:nil]; - +- (void)dealloc { [self.wkWebView setNavigationDelegate:nil]; [self.wkWebView setUIDelegate:nil]; if ([self isViewLoaded]) { diff --git a/README.md b/README.md index 573f037..d12eef2 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ KINWebBrowser KINWebBrowser is a web browser module for your apps. -Powered by [WKWebView](https://developer.apple.com/library/IOs/documentation/WebKit/Reference/WKWebView_Ref/index.html) on iOS 8. Backwards compatible with iOS 7 using [UIWebView](https://developer.apple.com/library/ios/documentation/Uikit/reference/UIWebView_Class/index.html). +Powered by [WKWebView](https://developer.apple.com/library/IOs/documentation/WebKit/Reference/WKWebView_Ref/index.html) on iOS 8. ![KINWebBrowser Screenshots](http://i.imgur.com/z1jkWKG.png) Features ------------------------ -* iOS 7 & 8 support for iPhone and iPad devices +* iOS 8 support for iPhone and iPad devices * Safari-like interface * Animated progress bar * Customizable UI including tint color @@ -53,7 +53,7 @@ Installation ###### Podfile ```ruby -platform :ios, '7.0' +platform :ios, '8.0' pod 'KINWebBrowser' ```