#import "ViewController.h"
#import <WebKit/WebKit.h>
#import "NSURLRequest+DummyInterface.h"
@interface ViewController ()<WKUIDelegate,WKNavigationDelegate,NSURLConnectionDataDelegate>
@property(nonatomic,strong)WKWebView *wkWebView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
self.wkWebView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
self.wkWebView.navigationDelegate = self;
self.wkWebView.UIDelegate = self;
// 2.加载网页
// NSString *indexPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
// NSString *appHtml = [NSString stringWithContentsOfFile:indexPath encoding:NSUTF8StringEncoding error:nil];
// NSURL *baseUrl = [NSURL fileURLWithPath:indexPath];
// [self.wkWebView loadHTMLString:appHtml baseURL:baseUrl];
// NSURL *url= [NSURL URLWithString:@"https://kyfw.12306.cn/otn/regist/init"];
// NSURL *url= [NSURL URLWithString:@"http://www.jianshu.com/u/2f02e0bb6464"];
NSURL *url= [NSURL URLWithString:@"http://106.37.173.33:8008/webtrade/trade/tradelogin.html?qdid=zjzx"];
NSURLRequest *req = [[NSURLRequest alloc]initWithURL:url];
[self.wkWebView loadRequest:req];
[self.view addSubview:self.wkWebView];
}
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
NSURLCredential *credential = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
}
}
- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{
if (!navigationAction.targetFrame.isMainFrame) {
[self.wkWebView loadRequest:navigationAction.request];
}
return nil;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
网友评论