Skip to content

Commit

Permalink
Merge pull request #551 from glukianets/master
Browse files Browse the repository at this point in the history
Bump target sdk version to 8.0 and migrate to WKWebView
  • Loading branch information
0xstragner authored Sep 14, 2019
2 parents 5504d80 + 5680136 commit 516bd02
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
----------

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions VK-ios-sdk.podspec
Original file line number Diff line number Diff line change
@@ -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" => "[email protected]" }
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'
Expand Down
9 changes: 7 additions & 2 deletions VK-ios-sdk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
1ACA6041B183FB7781AC6F07 /* VKUploadMessagesPhotoRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VKUploadMessagesPhotoRequest.h; sourceTree = "<group>"; };
1ACA60549B5805BC010388F6 /* VKCaptchaViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VKCaptchaViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -723,6 +726,7 @@
F3C7542F182133CC00964716 /* Frameworks */ = {
isa = PBXGroup;
children = (
15DF536A232BBBE600593625 /* WebKit.framework */,
F3C68F161C0C855C00E1EB5E /* Security.framework */,
F3769E701BE8E41C00AEC4AF /* SafariServices.framework */,
F3769E6E1BE8E41800AEC4AF /* CoreGraphics.framework */,
Expand Down Expand Up @@ -936,6 +940,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
ru,
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};
Expand Down
5 changes: 3 additions & 2 deletions example/VKSDKTestApplication.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
ru,
);
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};
Expand Down
6 changes: 3 additions & 3 deletions library/Source/Views/VKAuthorizeController.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ typedef NS_ENUM(NSInteger, VKAuthorizationType) {
/**
Controller for authorization through webview (if VK app not available)
*/
@interface VKAuthorizeController : UIViewController <UIWebViewDelegate>
@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)
Expand All @@ -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;
Expand Down
24 changes: 13 additions & 11 deletions library/Source/Views/VKAuthorizeController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#import "VKAuthorizeController.h"
#import "VKBundle.h"
#import <WebKit/WebKit.h>

NSString *VK_AUTHORIZE_URL_STRING = @"vkauthorize://authorize";

Expand Down Expand Up @@ -50,8 +51,8 @@ @interface VKSdk ()
+ (BOOL)processOpenInternalURL:(NSURL *)passedUrl validation:(BOOL)validation;
@end

@interface VKAuthorizeController ()
@property(nonatomic, strong) UIWebView *webView;
@interface VKAuthorizeController () <WKUIDelegate, WKNavigationDelegate>
@property(nonatomic, strong) WKWebView *webView;
@property(nonatomic, strong) NSString *appId;
@property(nonatomic, strong) NSString *scope;
@property(nonatomic, strong) NSURL *redirectUri;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 516bd02

Please sign in to comment.