Skip to content

Commit 41c434e

Browse files
committed
Switched deprecated UIWebView for WKWebView
1 parent 7bc0511 commit 41c434e

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
TargetAttributes = {
182182
97C146ED1CF9000F007C117D = {
183183
CreatedOnToolsVersion = 7.3.1;
184-
DevelopmentTeam = EP5N73U5P2;
184+
DevelopmentTeam = 599T4B53UD;
185185
SystemCapabilities = {
186186
com.apple.BackgroundModes = {
187187
enabled = 1;
@@ -195,6 +195,7 @@
195195
developmentRegion = English;
196196
hasScannedForEncodings = 0;
197197
knownRegions = (
198+
English,
198199
en,
199200
Base,
200201
);
@@ -431,7 +432,7 @@
431432
buildSettings = {
432433
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
433434
CURRENT_PROJECT_VERSION = 1;
434-
DEVELOPMENT_TEAM = EP5N73U5P2;
435+
DEVELOPMENT_TEAM = 599T4B53UD;
435436
ENABLE_BITCODE = NO;
436437
FRAMEWORK_SEARCH_PATHS = (
437438
"$(inherited)",
@@ -455,7 +456,7 @@
455456
buildSettings = {
456457
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
457458
CURRENT_PROJECT_VERSION = 1;
458-
DEVELOPMENT_TEAM = EP5N73U5P2;
459+
DEVELOPMENT_TEAM = 599T4B53UD;
459460
ENABLE_BITCODE = NO;
460461
FRAMEWORK_SEARCH_PATHS = (
461462
"$(inherited)",

ios/Classes/PSTCKAuthViewController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import <UIKit/UIKit.h>
10+
#import <WebKit/WebKit.h>
1011

1112
typedef void(^PSTCKAuthCallback)(void);
1213

ios/Classes/PSTCKAuthViewController.m

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
@interface PSTCKAuthViewController ()
1212

13-
@property(nonatomic, strong) UIWebView *authenticationWebView;
13+
@property(nonatomic, strong) WKWebView *authenticationWebView;
1414
@property(nonatomic, copy) PSTCKAuthCallback completion;
1515
@property(nonatomic, strong) NSURL *authURL;
1616

1717
@end
1818

19-
@interface PSTCKAuthViewController (UIWebViewDelegate) <UIWebViewDelegate>
19+
@interface PSTCKAuthViewController (WKNavigationDelegate) <WKNavigationDelegate, WKUIDelegate>
2020

2121
@end
2222

@@ -42,10 +42,17 @@ - (void)viewDidLoad {
4242

4343
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(tappedCancelButton:)];
4444
self.navigationItem.leftBarButtonItem = cancelButton;
45+
// Adds javascript to make content width the device width.
46+
NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
47+
WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
48+
WKUserContentController *wkUController = [[WKUserContentController alloc] init];
49+
[wkUController addUserScript:wkUScript];
50+
WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
51+
wkWebConfig.userContentController = wkUController;
4552

46-
self.authenticationWebView = [[UIWebView alloc] init];
47-
self.authenticationWebView.delegate = self;
48-
self.authenticationWebView.scalesPageToFit = NO;
53+
self.authenticationWebView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:wkWebConfig];
54+
self.authenticationWebView.UIDelegate = self;
55+
self.authenticationWebView.navigationDelegate = self;
4956
[self.view addSubview:self.authenticationWebView];
5057
[self.navigationController setNavigationBarHidden:NO animated:YES];
5158
self.navigationController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
@@ -71,11 +78,12 @@ - (void)tappedCancelButton:(id)cancelButton {
7178

7279
@end
7380

74-
@implementation PSTCKAuthViewController (UIWebViewDelegate)
81+
@implementation PSTCKAuthViewController (WKNavigationDelegate)
7582

76-
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
77-
#pragma unused(webView, navigationType)
78-
NSString *url = [[request URL] absoluteString];
83+
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
84+
#pragma unused(webView, navigationAction)
85+
NSURLRequest *request = navigationAction.request;
86+
NSString *url = [[request URL]absoluteString];
7987

8088
// Prevent loading URL if it is the redirectURL
8189
// The intention is to only requery 3DS auths
@@ -84,18 +92,21 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
8492
// Processing has finished?
8593
if (handlingRedirectURL) {
8694
self.completion();
95+
return decisionHandler(WKNavigationActionPolicyCancel);
96+
97+
}
98+
else {
99+
return decisionHandler(WKNavigationActionPolicyAllow);
87100
}
88-
89-
return !handlingRedirectURL;
90101
}
91102

92-
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
93-
#pragma unused(webView)
94-
95-
NSLog(@"%@", error);
96-
NSString * myString = error.description;
97-
NSLog(@"%@", myString);
98-
103+
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
104+
#pragma unused(webView, navigation)
105+
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
106+
}
107+
108+
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
109+
#pragma unused(webView, navigation)
99110
// Turn off network activity indicator upon failure to load web view
100111
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
101112

@@ -110,12 +121,4 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
110121
}
111122
}
112123

113-
- (void)webViewDidFinishLoad:(UIWebView *)webView {
114-
#pragma unused(webView)
115-
116-
// Turn off network activity indicator upon finishing web view load
117-
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
118-
119-
}
120-
121124
@end

0 commit comments

Comments
 (0)