From 5680136d8094bf5a0ffa4af09aecd0cf8a1a3693 Mon Sep 17 00:00:00 2001 From: Gleb Lukianets Date: Fri, 13 Sep 2019 16:26:10 +0300 Subject: [PATCH] Bump target sdk version to 8.0 and migrate to WKWebView --- README.md | 4 ++-- VK-ios-sdk.podspec | 4 ++-- VK-ios-sdk.xcodeproj/project.pbxproj | 9 +++++-- .../project.pbxproj | 5 ++-- library/Source/Views/VKAuthorizeController.h | 6 ++--- library/Source/Views/VKAuthorizeController.m | 24 ++++++++++--------- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index e9fa286c..1ce1d227 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ vk-ios-sdk ========== -Library for working with VK API, authorizing through VK app, using VK API methods. Supported iOS from 6.0 +Library for working with VK API, authorizing through VK app, using VK API methods. Supported iOS from 8.0 Prepare for Using VK SDK ---------- @@ -61,7 +61,7 @@ CocoaPods is a dependency manager for Objective-C, which automates and simplifie `Podfile` - platform :ios, '6.0' + platform :ios, '8.0' target 'YourProjectName' do pod 'VK-ios-sdk' end diff --git a/VK-ios-sdk.podspec b/VK-ios-sdk.podspec index 1546ee5a..557706b4 100755 --- a/VK-ios-sdk.podspec +++ b/VK-ios-sdk.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "VK-ios-sdk" - s.version = "1.4.6" + s.version = "1.5.0" s.summary = "Library for working with VK." s.homepage = "https://github.com/VKCOM/vk-ios-sdk" s.license = 'MIT' s.author = { "Roman Truba" => "dreddkr@gmail.com" } - s.platform = :ios, '6.0' + s.platform = :ios, '8.0' s.source = { :git => "https://github.com/VKCOM/vk-ios-sdk.git", :tag => s.version.to_s } s.source_files = 'library/source/**/*.{h,m}' s.public_header_files = 'library/source/**/*.h' diff --git a/VK-ios-sdk.xcodeproj/project.pbxproj b/VK-ios-sdk.xcodeproj/project.pbxproj index b92b95e5..6ee33aaf 100755 --- a/VK-ios-sdk.xcodeproj/project.pbxproj +++ b/VK-ios-sdk.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 132CF80019D2B3360084884D /* VKBundle.h in Copy Files */ = {isa = PBXBuildFile; fileRef = F3BACC5618659493003158DA /* VKBundle.h */; }; 132CF80719D2B3360084884D /* VKPermissions.h in Copy Files */ = {isa = PBXBuildFile; fileRef = F3EEFFA41827B726000BB525 /* VKPermissions.h */; }; 132CF80A19D2B3360084884D /* VKSdkVersion.h in Copy Files */ = {isa = PBXBuildFile; fileRef = F3EEFFBC1827C582000BB525 /* VKSdkVersion.h */; }; + 15DF536B232BBBE600593625 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15DF536A232BBBE600593625 /* WebKit.framework */; }; 183C475918B2F1ED00F978DB /* VKAccessToken.m in Sources */ = {isa = PBXBuildFile; fileRef = F3C7549A18226ABB00964716 /* VKAccessToken.m */; }; 183C475A18B2F1ED00F978DB /* VKBatchRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = F3D38E7E183F7B4800D05079 /* VKBatchRequest.m */; }; 183C475B18B2F1ED00F978DB /* VKBundle.m in Sources */ = {isa = PBXBuildFile; fileRef = F3BACC5718659493003158DA /* VKBundle.m */; }; @@ -330,6 +331,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 15DF536A232BBBE600593625 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; }; 1ACA602BF516D3FC45609A2B /* VKAuthorizeController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VKAuthorizeController.m; sourceTree = ""; }; 1ACA6041B183FB7781AC6F07 /* VKUploadMessagesPhotoRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VKUploadMessagesPhotoRequest.h; sourceTree = ""; }; 1ACA60549B5805BC010388F6 /* VKCaptchaViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VKCaptchaViewController.h; sourceTree = ""; }; @@ -467,6 +469,7 @@ files = ( F3C68F171C0C855C00E1EB5E /* Security.framework in Frameworks */, F3769E711BE8E41C00AEC4AF /* SafariServices.framework in Frameworks */, + 15DF536B232BBBE600593625 /* WebKit.framework in Frameworks */, F3769E6F1BE8E41800AEC4AF /* CoreGraphics.framework in Frameworks */, F346704B1B8B7C70003EF74B /* Foundation.framework in Frameworks */, F346704A1B8B7C6B003EF74B /* UIKit.framework in Frameworks */, @@ -723,6 +726,7 @@ F3C7542F182133CC00964716 /* Frameworks */ = { isa = PBXGroup; children = ( + 15DF536A232BBBE600593625 /* WebKit.framework */, F3C68F161C0C855C00E1EB5E /* Security.framework */, F3769E701BE8E41C00AEC4AF /* SafariServices.framework */, F3769E6E1BE8E41800AEC4AF /* CoreGraphics.framework */, @@ -936,6 +940,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ru, @@ -1349,7 +1354,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 6.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; @@ -1381,7 +1386,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 6.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; diff --git a/example/VKSDKTestApplication.xcodeproj/project.pbxproj b/example/VKSDKTestApplication.xcodeproj/project.pbxproj index d1eae6b6..2156d111 100755 --- a/example/VKSDKTestApplication.xcodeproj/project.pbxproj +++ b/example/VKSDKTestApplication.xcodeproj/project.pbxproj @@ -239,6 +239,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ru, ); @@ -372,7 +373,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; @@ -404,7 +405,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; diff --git a/library/Source/Views/VKAuthorizeController.h b/library/Source/Views/VKAuthorizeController.h index dba98857..49bcfee1 100755 --- a/library/Source/Views/VKAuthorizeController.h +++ b/library/Source/Views/VKAuthorizeController.h @@ -60,10 +60,10 @@ typedef NS_ENUM(NSInteger, VKAuthorizationType) { /** Controller for authorization through webview (if VK app not available) */ -@interface VKAuthorizeController : UIViewController +@interface VKAuthorizeController : UIViewController /** -Causes UIWebView in standard UINavigationController be presented in SDK delegate +Causes web view in standard UINavigationController be presented in SDK delegate @param appId Identifier of VK application @param permissions Permissions that user specified for application @param revoke If YES, user will see permissions list and allow to logout (if logged in already) @@ -75,7 +75,7 @@ Causes UIWebView in standard UINavigationController be presented in SDK delegate displayType:(VKDisplayType)displayType; /** -Causes UIWebView in standard UINavigationController be presented for user validation +Causes web view in standard UINavigationController be presented for user validation @param validationError validation error returned by API */ + (void)presentForValidation:(VKError *)validationError; diff --git a/library/Source/Views/VKAuthorizeController.m b/library/Source/Views/VKAuthorizeController.m index fc5d998d..53e5f0f9 100755 --- a/library/Source/Views/VKAuthorizeController.m +++ b/library/Source/Views/VKAuthorizeController.m @@ -22,6 +22,7 @@ #import "VKAuthorizeController.h" #import "VKBundle.h" +#import NSString *VK_AUTHORIZE_URL_STRING = @"vkauthorize://authorize"; @@ -50,8 +51,8 @@ @interface VKSdk () + (BOOL)processOpenInternalURL:(NSURL *)passedUrl validation:(BOOL)validation; @end -@interface VKAuthorizeController () -@property(nonatomic, strong) UIWebView *webView; +@interface VKAuthorizeController () +@property(nonatomic, strong) WKWebView *webView; @property(nonatomic, strong) NSString *appId; @property(nonatomic, strong) NSString *scope; @property(nonatomic, strong) NSURL *redirectUri; @@ -157,11 +158,11 @@ - (void)loadView { _warningLabel.text = VKLocalizedString(@"Please check your internet connection"); [view addSubview:_warningLabel]; - _webView = [[UIWebView alloc] initWithFrame:view.bounds]; - _webView.delegate = self; + _webView = [[WKWebView alloc] initWithFrame:view.bounds]; + _webView.UIDelegate = self; + _webView.navigationDelegate = self; _webView.hidden = YES; _webView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; - _webView.scalesPageToFit = YES; _webView.scrollView.bounces = NO; _webView.scrollView.clipsToBounds = NO; [view addSubview:_webView]; @@ -205,7 +206,8 @@ - (void)startLoading { #pragma mark Web view work -- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { + NSURLRequest *request = navigationAction.request; self.lastRequest = request; NSString *urlString = [[request URL] absoluteString]; self.statusBar.text = urlString; @@ -220,12 +222,12 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *) [self.validationError.request cancel]; } }]; - return NO; + decisionHandler(WKNavigationActionPolicyCancel); } - return YES; + decisionHandler(WKNavigationActionPolicyAllow); } -- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { +- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error { if (self.finished) return; if ([error code] != NSURLErrorCancelled) { self.warningLabel.hidden = NO; @@ -245,7 +247,7 @@ - (void)setRightBarButtonActivity { [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:activityView] animated:YES]; } -- (void)webViewDidFinishLoad:(UIWebView *)webView { +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { [self makeViewport]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (300 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^(void) { _warningLabel.hidden = YES; @@ -256,7 +258,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView { - (void)makeViewport { NSString *javaScript = [NSString stringWithFormat:@"viewport = document.querySelector('meta[name=viewport]'); viewport.setAttribute('content', 'width = %d, height = %d, initial-scale = 1.0, maximum-scale = 1.0, minimum-scale = 1.0, user-scalable=yes');", (int) self.webView.frame.size.width, (int) self.webView.frame.size.height]; - [_webView stringByEvaluatingJavaScriptFromString:javaScript]; + [_webView evaluateJavaScript:javaScript completionHandler:nil]; } #pragma mark Cancelation and dismiss