Skip to content

Commit

Permalink
For login, use WKWebView (and private browsing) instead of UIWebView
Browse files Browse the repository at this point in the history
  • Loading branch information
t0rst committed Aug 1, 2018
1 parent dc30ae7 commit 9d2a9b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
15 changes: 0 additions & 15 deletions HelloOBP-iOS/Res/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1518,25 +1518,10 @@ To find out more visit the openbankproject.</string>
<view key="view" contentMode="scaleToFill" id="fbV-dJ-7KL">
<rect key="frame" x="0.0" y="0.0" width="320" height="504"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<webView contentMode="scaleAspectFit" translatesAutoresizingMaskIntoConstraints="NO" id="Jlg-Jo-ntH">
<rect key="frame" x="0.0" y="0.0" width="320" height="504"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</webView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="Jlg-Jo-ntH" secondAttribute="trailing" id="Sjp-a5-jTP"/>
<constraint firstItem="Jlg-Jo-ntH" firstAttribute="leading" secondItem="fbV-dJ-7KL" secondAttribute="leading" id="Ws2-NS-Vb0"/>
<constraint firstItem="FuB-nW-Aex" firstAttribute="top" secondItem="Jlg-Jo-ntH" secondAttribute="bottom" id="khW-0G-aRe"/>
<constraint firstItem="Jlg-Jo-ntH" firstAttribute="top" secondItem="81C-s1-VfC" secondAttribute="bottom" id="oR7-uZ-a8r"/>
</constraints>
</view>
<extendedEdge key="edgesForExtendedLayout"/>
<navigationItem key="navigationItem" id="ibp-r7-yEf"/>
<connections>
<outlet property="webView" destination="Jlg-Jo-ntH" id="eZ7-W8-6Wy"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qxP-Df-DJg" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down
45 changes: 30 additions & 15 deletions HelloOBP-iOS/UI/LoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@

#import "LoginViewController.h"

#import <WebKit/WebKit.h>
#import <OBPKit/OBPKit.h>
#import "DefaultServerDetails.h"



@interface LoginViewController () <UIWebViewDelegate, OBPWebViewProvider>
@property(nonatomic, retain) IBOutlet UIWebView *webView;
@interface LoginViewController () <OBPWebViewProvider, WKNavigationDelegate>
@end



@implementation LoginViewController
{
WKWebView* _webView;
OBPServerInfo* _serverInfo;
NSString* _APIBase;
OBPSession* _session;
Expand All @@ -44,11 +45,14 @@ - (void)viewDidLoad
_APIBase = _serverInfo.APIBase;

// 3. initialize the webview and add it to the view

self.webView.delegate = self;
self.webView.scalesPageToFit = YES;
self.webView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:self.webView];
CGRect frame = self.view.bounds;
_webView = [[WKWebView alloc] initWithFrame: frame];
_webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_webView.configuration.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
_webView.configuration.preferences.javaScriptCanOpenWindowsAutomatically = NO;
_webView.navigationDelegate = self;
[self.view addSubview: _webView];

_session.webViewProvider = self;

// 4. Kick off session authentication
Expand All @@ -71,7 +75,7 @@ - (void)showURL:(NSURL*)url filterNavWith:(OBPWebNavigationFilter)onwardNavigati
{
_callbackFilter = onwardNavigationFilter;
_cancelNotifier = cancelNotifier;
[self.webView loadRequest: [NSURLRequest requestWithURL: url]];
[_webView loadRequest: [NSURLRequest requestWithURL: url]];
}

- (void)resetWebViewProvider
Expand All @@ -88,14 +92,25 @@ - (void)didReceiveMemoryWarning
// Dispose of any resources that can be recreated.
}

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction decisionHandler:(void(^)(WKNavigationActionPolicy))decisionHandler
{
if (_callbackFilter != nil)
if (_callbackFilter(request.URL))
return NO;

return YES;
WKNavigationActionPolicy policy = WKNavigationActionPolicyAllow;
WKNavigationType navType = navigationAction.navigationType;
NSURL* navURL;

OBP_LOG_IF(0, @"\nnavigationAction: %@", navigationAction);

if (navType == WKNavigationTypeLinkActivated
|| navType == WKNavigationTypeOther)
{
navURL = navigationAction.request.URL;
if (_callbackFilter != nil)
if (_callbackFilter(navURL))
policy = WKNavigationActionPolicyCancel;
}

decisionHandler(policy);
}

@end

0 comments on commit 9d2a9b1

Please sign in to comment.