我在WKWebView中拦截某些HTTP请求时遇到问题(我使用目标C)。似乎未调用definePolicyForNavigationAction。有人可以帮我解决我可能做错的事情吗?
我首先从库中将WKWebview组件添加到Main.Storyboard
然后我将以下内容添加到ViewController.h
#import <WebKit/WebKit.h>
@interface ViewController : UIViewController<UIAlertViewDelegate, WKUIDelegate, WKNavigationDelegate>
@property (strong, nonatomic) IBOutlet WKWebView *webView;
@end
然后到ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
webView = [[WKWebView alloc] initWithFrame:[[self view] bounds]];
NSURL *url = [NSURL URLWithString:@"https://url.com"];
NSURLRequest *urlReq = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlReq];
self.view = webView;
}
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
NSLog(@"decidePolicyForNavigationAction");
if (decisionHandler) {
NSLog(@"decidePolicyForNavigationAction2");
decisionHandler(WKNavigationActionPolicyAllow);
}
}
答案 0 :(得分:0)
更改此:
[webView loadRequest:urlReq];
对此:
webView.navigationDelegate = self;
[webView loadRequest:urlReq];
答案 1 :(得分:0)
好吧,我终于找到了问题:) 此属性阻止了我的NSLog:“ OS_ACTIVITY_MODE”:“禁用