diff --git a/Demo/SVWeb-Info.plist b/Demo/SVWeb-Info.plist index 44be994..fc9f237 100644 --- a/Demo/SVWeb-Info.plist +++ b/Demo/SVWeb-Info.plist @@ -11,13 +11,15 @@ CFBundleIconFile CFBundleIdentifier - com.yourcompany.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName ${PRODUCT_NAME} CFBundlePackageType APPL + CFBundleShortVersionString + $(MARKETING_VERSION) CFBundleSignature ???? CFBundleVersion diff --git a/Demo/SVWeb.xcodeproj/project.pbxproj b/Demo/SVWeb.xcodeproj/project.pbxproj index 9072982..04e0536 100755 --- a/Demo/SVWeb.xcodeproj/project.pbxproj +++ b/Demo/SVWeb.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ 28AD73600D9D9599002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD735F0D9D9599002E5188 /* MainWindow.xib */; }; 28C286E10D94DF7D0034E888 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28C286E00D94DF7D0034E888 /* ViewController.m */; }; 28F335F11007B36200424DE2 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28F335F01007B36200424DE2 /* ViewController.xib */; }; + AB41CEB9245A6FC90094FF87 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB41CEB8245A6FC90094FF87 /* WebKit.framework */; }; D53D8F1316A8688600711E30 /* SVWebViewController.strings in Resources */ = {isa = PBXBuildFile; fileRef = D53D8F1516A8688600711E30 /* SVWebViewController.strings */; }; D5FA63C516A8707A0087531C /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D5FA63C416A8707A0087531C /* Default-568h@2x.png */; }; /* End PBXBuildFile section */ @@ -71,6 +72,7 @@ 6DAD2E4EAB184F72ACE29999 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 8D1107310486CEB800E47090 /* SVWeb-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "SVWeb-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = ""; }; A0667BBC457D4307AC51AC26 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; + AB41CEB8245A6FC90094FF87 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; D53D8F1716A868C900711E30 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/SVWebViewController.strings; sourceTree = ""; }; D53D8F1816A8693200711E30 /* es-ES */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-ES"; path = "es-ES.lproj/SVWebViewController.strings"; sourceTree = ""; }; D53D8F1916A8693A00711E30 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/SVWebViewController.strings; sourceTree = ""; }; @@ -84,6 +86,7 @@ files = ( 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */, 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */, + AB41CEB9245A6FC90094FF87 /* WebKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -206,6 +209,7 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( + AB41CEB8245A6FC90094FF87 /* WebKit.framework */, 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */, 1D30AB110D05D00D00671497 /* Foundation.framework */, 6DAD2E4EAB184F72ACE29999 /* libPods.a */, @@ -239,17 +243,13 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0500; + LastUpgradeCheck = 1140; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SVWeb" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 1; knownRegions = ( - English, - Japanese, - French, - German, en, fr, de, @@ -271,6 +271,7 @@ sv, vi, zh_CN, + Base, ); mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; projectDirPath = ""; @@ -353,6 +354,8 @@ GCC_PREFIX_HEADER = SVWeb_Prefix.pch; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INFOPLIST_FILE = "SVWeb-Info.plist"; + MARKETING_VERSION = 0.3; + PRODUCT_BUNDLE_IDENTIFIER = "com.yourcompany.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = SVWeb; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -362,13 +365,37 @@ C01FCF4F08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ENABLE_OBJC_ARC = NO; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = c99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; diff --git a/Demo/SVWeb_Prefix.pch b/Demo/SVWeb_Prefix.pch index 12d2363..3013e0e 100644 --- a/Demo/SVWeb_Prefix.pch +++ b/Demo/SVWeb_Prefix.pch @@ -10,4 +10,5 @@ #ifdef __OBJC__ #import #import + #import #endif diff --git a/Demo/main.m b/Demo/main.m index 53f8756..702e650 100644 --- a/Demo/main.m +++ b/Demo/main.m @@ -7,6 +7,7 @@ // #import +#import int main(int argc, char *argv[]) { @autoreleasepool { diff --git a/SVWebViewController/SVModalWebViewController.h b/SVWebViewController/SVModalWebViewController.h index 0aba971..d74ea66 100644 --- a/SVWebViewController/SVModalWebViewController.h +++ b/SVWebViewController/SVModalWebViewController.h @@ -6,7 +6,7 @@ // // https://github.com/samvermette/SVWebViewController -#import +#import @class SVWebViewController; @class SVModalWebViewController; @@ -16,7 +16,7 @@ typedef NS_ENUM(NSUInteger, SVWebViewControllerDismissButtonStyle) { SVWebViewControllerDismissButtonStyleCancel }; -@protocol SVModalWebViewControllerDelegate +@protocol SVModalWebViewControllerDelegate @optional - (void)controllerDidPressDoneButton:(SVModalWebViewController *)controller; diff --git a/SVWebViewController/SVModalWebViewController.m b/SVWebViewController/SVModalWebViewController.m index c1e081b..a7adc9d 100644 --- a/SVWebViewController/SVModalWebViewController.m +++ b/SVWebViewController/SVModalWebViewController.m @@ -83,11 +83,11 @@ - (UIBarButtonItem *)barButtonItemForDismissButtonStyle:(SVWebViewControllerDism #pragma mark - Delegate -- (void)setWebViewDelegate:(id)webViewDelegate { +- (void)setWebViewDelegate:(id)webViewDelegate { self.webViewController.delegate = webViewDelegate; } -- (id)webViewDelegate { +- (id)webViewDelegate { return self.webViewController.delegate; } diff --git a/SVWebViewController/SVWebViewController.h b/SVWebViewController/SVWebViewController.h index 26e76c1..1415f28 100644 --- a/SVWebViewController/SVWebViewController.h +++ b/SVWebViewController/SVWebViewController.h @@ -6,14 +6,16 @@ // // https://github.com/samvermette/SVWebViewController +#import + @interface SVWebViewController : UIViewController - (instancetype)initWithAddress:(NSString *)urlString; - (instancetype)initWithURL:(NSURL *)URL; - (instancetype)initWithURLRequest:(NSURLRequest *)request; -@property (nonatomic, weak) id delegate; -@property (nonatomic, readonly) UIWebView *webView; +@property (nonatomic, weak) id delegate; +@property (nonatomic, readonly) WKWebView *webView; @property (nonatomic, strong) NSMutableArray *activities; @end diff --git a/SVWebViewController/SVWebViewController.m b/SVWebViewController/SVWebViewController.m index f5c8477..4b51a35 100644 --- a/SVWebViewController/SVWebViewController.m +++ b/SVWebViewController/SVWebViewController.m @@ -10,7 +10,7 @@ #import "SVWebViewControllerActivitySafari.h" #import "SVWebViewController.h" -@interface SVWebViewController () +@interface SVWebViewController () @property (nonatomic, strong) UIBarButtonItem *backBarButtonItem; @property (nonatomic, strong) UIBarButtonItem *forwardBarButtonItem; @@ -18,7 +18,7 @@ @interface SVWebViewController () @property (nonatomic, strong) UIBarButtonItem *stopBarButtonItem; @property (nonatomic, strong) UIBarButtonItem *actionBarButtonItem; -@property (nonatomic, strong) UIWebView *webView; +@property (nonatomic, strong) WKWebView *webView; @property (nonatomic, strong) NSURLRequest *request; @end @@ -31,7 +31,7 @@ @implementation SVWebViewController - (void)dealloc { [self.webView stopLoading]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; - self.webView.delegate = nil; + self.webView.navigationDelegate = nil; self.delegate = nil; } @@ -112,11 +112,10 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfa #pragma mark - Getters -- (UIWebView*)webView { +- (WKWebView*)webView { if(!_webView) { - _webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds]; - _webView.delegate = self; - _webView.scalesPageToFit = YES; + _webView = [[WKWebView alloc] initWithFrame:[UIScreen mainScreen].bounds]; + _webView.navigationDelegate = self; } return _webView; } @@ -216,47 +215,66 @@ - (void)updateToolbarItems { } } -#pragma mark - UIWebViewDelegate +#pragma mark - WKNavigationDelegate -- (void)webViewDidStartLoad:(UIWebView *)webView { +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation +{ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; [self updateToolbarItems]; - - if ([self.delegate respondsToSelector:@selector(webViewDidStartLoad:)]) { - [self.delegate webViewDidStartLoad:webView]; + + if ([self.delegate respondsToSelector:@selector(webView:didStartProvisionalNavigation:)]) { + [self.delegate webView:webView didStartProvisionalNavigation:navigation]; } } - -- (void)webViewDidFinishLoad:(UIWebView *)webView { +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation +{ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; - + + __weak SVWebViewController *weakSelf = self; + __block void (^finalBlock)(void) = ^{ + SVWebViewController *strongSelf = weakSelf; + if (strongSelf) { + [strongSelf updateToolbarItems]; + + if ([strongSelf.delegate respondsToSelector:@selector(webView:didFinishNavigation:)]) { + [strongSelf.delegate webView:webView didFinishNavigation:navigation]; + } + } + }; + if (self.navigationItem.title == nil) { - self.navigationItem.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"]; - } - - [self updateToolbarItems]; - - if ([self.delegate respondsToSelector:@selector(webViewDidFinishLoad:)]) { - [self.delegate webViewDidFinishLoad:webView]; + id evalCompletion = ^(id _Nullable result, NSError * _Nullable error) { + SVWebViewController *strongSelf = weakSelf; + if (strongSelf && !error && result) { + strongSelf.navigationItem.title = [NSString stringWithFormat:@"%@", result]; + } + finalBlock(); + }; + [webView evaluateJavaScript:@"document.title" + completionHandler:evalCompletion]; + } else { + finalBlock(); } } -- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { +- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error +{ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; [self updateToolbarItems]; - - if ([self.delegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) { - [self.delegate webView:webView didFailLoadWithError:error]; + + if ([self.delegate respondsToSelector:@selector(webView:didFailNavigation:withError:)]) { + [self.delegate webView:webView didFailNavigation:navigation withError:error]; } } -- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { - if ([self.delegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) { - return [self.delegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType]; +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler +{ + if ([self.delegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:decisionHandler:)]) { + [self.delegate webView:webView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler]; + } else { + decisionHandler(WKNavigationActionPolicyAllow); } - - return YES; } #pragma mark - Target actions @@ -279,7 +297,7 @@ - (void)stopTapped:(UIBarButtonItem *)sender { } - (void)actionButtonTapped:(id)sender { - NSURL *url = self.webView.request.URL ? self.webView.request.URL : self.request.URL; + NSURL *url = self.webView.URL ? self.webView.URL : self.request.URL; if (url != nil) { if ([[url absoluteString] hasPrefix:@"file:///"]) { UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:url]; diff --git a/SVWebViewController/UIActivities/SVWebViewControllerActivity.h b/SVWebViewController/UIActivities/SVWebViewControllerActivity.h index 1d643e8..d75aa4f 100644 --- a/SVWebViewController/UIActivities/SVWebViewControllerActivity.h +++ b/SVWebViewController/UIActivities/SVWebViewControllerActivity.h @@ -6,7 +6,7 @@ // // -#import +#import @interface SVWebViewControllerActivity : UIActivity