2
0

Enable support for internal actions from URLs.

This commit is contained in:
Maarten Billemont
2020-04-25 17:10:20 -04:00
parent 10b205c541
commit 8bedcedfaf
8 changed files with 292 additions and 159 deletions

View File

@@ -17,6 +17,7 @@
//==============================================================================
#import "MPWebViewController.h"
#import "MPiOSAppDelegate.h"
@implementation MPWebViewController
@@ -57,6 +58,18 @@
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
decisionHandler:(void ( ^ )(WKNavigationActionPolicy))decisionHandler {
if ([navigationAction.request.mainDocumentURL.scheme isEqualToString:@"masterpassword"]) {
[[MPiOSAppDelegate get] openURL:navigationAction.request.mainDocumentURL];
decisionHandler( WKNavigationActionPolicyCancel );
return;
}
decisionHandler( WKNavigationActionPolicyAllow );
}
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
self.webNavigationItem.title = webView.URL.host;
@@ -77,7 +90,7 @@
}
[self.webNavigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(openURL:)]];
initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector( action: )]];
[webView evaluateJavaScript:@"document.title" completionHandler:^(id o, NSError *error) {
self.webNavigationItem.prompt = [o description];
}];
@@ -85,7 +98,7 @@
#pragma mark - Actions
- (IBAction)openURL:(id)sender {
- (IBAction)action:(id)sender {
UIAlertController *controller = [UIAlertController new];
controller.title = self.webView.URL.host;