iOS9 访问http网络

如果在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