【发布时间】:2019-01-23 21:31:09
【问题描述】:
我正在开发一个应用程序,其中一些代码继承自其他开发人员,并带有一个加载 html 文件的 Web 视图。
在 html 文件中是电话号码和网页链接。长按会打开电话号码,但没有打开 html 链接。
我希望它们通过短按打开,但短按没有任何反应。如果我长按,系统对话框会弹出一个“打开”选项,但按“打开”没有任何作用。
这是我刚才的代码:
#import "IntroductionViewController.h"
@interface IntroductionViewController () <WKNavigationDelegate, WKUIDelegate>
@end
@implementation IntroductionViewController
@synthesize html_file_name;
@synthesize web_view;
@synthesize spinner;
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBarHidden = NO;
[self setTitle:_title_string];
[self.web_view bringSubviewToFront:spinner];
[spinner setHidden:NO];
[spinner startAnimating];
NSURL *url = [[NSBundle mainBundle] URLForResource:html_file_name withExtension:@"html"];
[self.web_view loadRequest:[NSURLRequest requestWithURL:url]];
self.web_view.navigationDelegate = self;
self.web_view.UIDelegate = self;
}
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
[spinner setHidden:YES];
[spinner stopAnimating];
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
[spinner setHidden:YES];
[spinner stopAnimating];
}
- (BOOL)webView:(WKWebView *)webView shouldStartLoadWithRequest (NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"called here");
if (navigationType == UIWebViewNavigationTypeLinkClicked ) {
UIApplication *application = [UIApplication sharedApplication];
[application openURL:[request URL] options:@{} completionHandler:nil];
return YES;
}
return YES;
}
@end
“shouldStartLoadWithRequest”永远不会被调用。
【问题讨论】:
标签: ios objective-c wkwebview