编译器版本:XCode 8.3.1
IOS版本:10.2
使用UIWebView显示网页失败,提示:App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
新特性要求App内访问网络请求,要采用 HTTPS 协议,如果网页支持https协议,则改为https访问,如果不支持https则使用以下方法:
1.在Info.plist右键添加一行Key为:App Transport Security Settings,Type为:Dictionary
2.在App Transport Security Settings下添加字Key为:Allow Arbitrary Loads,Type为:Boolean,Value为:YES
重新运行就可以加载成功了。
// // WebViewController.m // 网页显示界面 // // Created by dcr on 2017/3/11. // Copyright © 2017年. All rights reserved. // #import "WebViewController.h" @interface WebViewController ()<UIWebViewDelegate> @property (weak, nonatomic) IBOutlet UIWebView *webView; @end @implementation WebViewController - (instancetype)initWithUrl:(NSString *)url{ self = [super init]; if(self){ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; [_webView loadRequest:request]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. _webView.frame = self.view.frame; _webView.delegate = self; NSLog(@"url = %@", _url); if(_url != nil){ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_url]]; [_webView loadRequest:request]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } //UIWebViewDelegate - (void)webViewDidStartLoad:(UIWebView *)webView{ NSLog(@"webViewDidStartLoad"); } - (void)webViewDidFinishLoad:(UIWebView *)webView{ NSLog(@"webViewDidFinishLoad"); } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ NSLog(@"didFailLoadWithError"); } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end