【ios编程报错处理-1】错误提示:App transport security has blocked a exceptions can be configured via your app's

来源:互联网 发布:2015最好的网络机顶盒 编辑:程序博客网 时间:2024/06/16 12:33

更新到Xcode7后大部分会发现自己的项目的数据加载出现了问题,控制台提示:
App transport security has blocked a exceptions can be configured via your app's info.plist file.

因为iOS9将不采用默认的http等不安全的请求。在iOS9 中,苹果将原http协议改成了https协议,使用 TLS1.2 SSL加密请求数据。
2种方式(相同结果)可以解决这个问题:

方式一:添加代码方式

  1. 可以在Info.plist文件中加入以下代码,来解决这个运行的问题。打开Info.plist文件的方式是:
    这里写图片描述

打开后可以看到:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict>    <key>NSAppTransportSecurity</key>    <dict>        <key>NSAllowsArbitraryLoads</key>        <true/>    </dict>    <key>CFBundleDevelopmentRegion</key>    <string>en</string>    <key>CFBundleExecutable</key>    <string>$(EXECUTABLE_NAME)</string>    <key>CFBundleIdentifier</key>    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>    <key>CFBundleInfoDictionaryVersion</key>    <string>6.0</string>    <key>CFBundleName</key>    <string>$(PRODUCT_NAME)</string>    <key>CFBundlePackageType</key>    <string>APPL</string>    <key>CFBundleShortVersionString</key>    <string>1.0</string>    <key>CFBundleSignature</key>    <string>????</string>    <key>CFBundleVersion</key>    <string>1</string>    <key>LSRequiresIPhoneOS</key>    <true/>    <key>UILaunchStoryboardName</key>    <string>LaunchScreen</string>    <key>UIMainStoryboardFile</key>    <string>Main</string>    <key>UIRequiredDeviceCapabilities</key>    <array>        <string>armv7</string>    </array>    <key>UISupportedInterfaceOrientations</key>    <array>        <string>UIInterfaceOrientationPortrait</string>        <string>UIInterfaceOrientationLandscapeLeft</string>        <string>UIInterfaceOrientationLandscapeRight</string>    </array></dict></plist>

在 这里面添加以下代码即可:

<key>NSAppTransportSecurity</key><dict   <key>NSAllowsArbitraryLoads</key>   <true/></dict>

方法二:可视化操作方式

选中项目中的Info.plist文件后,
这里写图片描述
在上面的 information property list 右边的+号单击,创建一个新的类别,然后将NSAppTransportSecurity复制进去,同样单击NSAppTransportSecurity右边的+号新建,将NSAllowsArbitraryLoads复制进去,在 type 类型里选择 Boolean 型,value 选择为YES 即可。

效果图:
这里写图片描述

0 0
原创粉丝点击