iOS9 访问http网络

文章详细介绍了如何在Xcode9环境下,通过修改Info.plist文件中的NSAppTransportSecurity设置,实现从HTTP请求到HTTPS的兼容性转换,确保App能够正常联网并访问资源。

如果在Xcode 9之前使用的时http请求,那么在XCode 9上编译的App是不能联网的,会提示如下错误:

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.
修 改方法是要么使服务器支持https访问,要么关闭https的使用。第一种方法对于个人开发者来说代价还是比较大的,因此推荐使用后面一种方法,具体的 做法是:在工程的Info.plist文件里添加NSAppTransportSecurity(xcode7.2改为:App Transport Security Settings)字典类型的,添加一个元素:key为 NSAllowsArbitraryLoads(xcode7.2改为:Allow Arbitrary Loads),值为YES。
 
修改后http 和 https都可以访问。
 
访问代码:配置后

- (void)afterSet

{

    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];

   NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.dianping.com/citylist"]];

   [webView loadRequest:request];

    [self.view addSubview:webView];

}

转载于:https://www.cnblogs.com/sunflower-lhb/p/4997062.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值