本人是刚入门的新手,昨天在项目中遇见一个问题,处理了很久才解决,希望写出来能帮助刚入门的新手
在项目中把app的版本信息以json放在服务器xxx.html的文件中,在app登录的时候获取版本信息
xxx.html
{
"ios": {"ver": "1.0.5"},
}
在app端通过来获取服务器端的版本号
NSURL *url = [NSURL URLWithString:@"http://xxxx.xxx.net/xxx/ xxx.html"];
return [[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil] objectFromJSONString];
return [[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil] objectFromJSONString];
但是发现返回值为nil,但是在网页中能打开网页,并没有错的,写到这里都懵逼了 项目有中并没有报错
最后发现IOS6引入了APP Transport Security(ATS),新特性要求app内访问的网络必须使用HTTPS协议
但是项目中是HTTP协议,使用私有加密方式保证数据安全 ,改成HTTPS协议传输太麻烦了
打开项目的 Info.plist中添加NSAppTransportSecurity类型Dictionary。
在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES。
但是有些小伙伴们在info.plist可能找不到NSAppTransportSecurity是因为
1.Xcode7.0中这项设定的名称为:NSAppTransportSecurity2.Xcode7.1之后这项设定的名称为:App Transport Security Settings
1.Xcode7.0设置如下
1.在 Info.plist中添加NSAppTransportSecurity类型Dictionary。
2. 在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES。
2. Xcode7.1之后设置如下
1.在 Info.plist点击图片中的+
2.找到App Transport Security Settings
3.在App Transport Security Settings下添加Allows Arbitrary Loads类型Boolean,值设为YES。
通过测试不会再返回nil 则能获取xxx.html文件的json
本人写的不好,请大家多多指导