//
// ViewController.m
// wkweb
//
// Created by 柏超曾 on 2017/8/29.
// Copyright © 2017年 柏超曾. All rights reserved.
//
#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
iOS wkwebview 忽略不受信任的https证书
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 之前也是使用UIWebView,但是近期使用时碰到了问题,所以就想着更换成WKWebView。都知道WKWebVi...
- 1.iOS7https://support.apple.com/zh-cn/HT2030652.ios8https...
- 首先要在文件中设置这个参数:(联网) 遵循这个代理 加上这俩个参数 pragma mark - UIWebView...
- Retrofit应该是目前最火的联网框架,但是内部还是使用的OKHttp,在这总结一下常用的配置。 做Cookie...