解开XCode开发工具的http协议限制问题

解开XCode开发工具的http协议限制问题

问题内容

使用XCode8.1开发IOS应用,使用WebView做一个网页demo,结果中途出现很多问题,第一是发现NSURL在XCode8.1的swift3版本下需要用URL替代,另外一个就是XCode默认不开启http请求的问题。运行日志内容如下:

objc[9876]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x118128998) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x117f4dd38). One of the two will be used. Which one is undefined.
2016-11-07 20:28:06.887 test3[9876:357348] 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.

最下面的内容意思就是:

应用程序默认暂时屏蔽了不安全的HTTP协议(http:/ /)。如果想允许,可以通过您的应用程序的Info.plist文件配置。

解决

使用Open As Source Code的方式打开项目根目录下的info.plist文件,在最后结束的位置加入:

    <key>NSAppTransportSecuritykey>
    <dict>
        <key>NSAllowsArbitraryLoadskey>
        <true/>
    dict>

下面是全部文件内容,可以参考增加的位置:



<plist version="1.0">
<dict>
    <key>LSApplicationCategoryTypekey>
    <string>string>
    <key>CFBundleDisplayNamekey>
    <string>string>
    <key>CFBundleDevelopmentRegionkey>
    <string>enstring>
    <key>CFBundleExecutablekey>
    <string>$(EXECUTABLE_NAME)string>
    <key>CFBundleIdentifierkey>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)string>
    <key>CFBundleInfoDictionaryVersionkey>
    <string>6.0string>
    <key>CFBundleNamekey>
    <string>$(PRODUCT_NAME)string>
    <key>CFBundlePackageTypekey>
    <string>APPLstring>
    <key>CFBundleShortVersionStringkey>
    <string>1.0string>
    <key>CFBundleVersionkey>
    <string>1string>
    <key>LSRequiresIPhoneOSkey>
    <true/>
    <key>UILaunchStoryboardNamekey>
    <string>LaunchScreenstring>
    <key>UIMainStoryboardFilekey>
    <string>Mainstring>
    <key>UIRequiredDeviceCapabilitieskey>
    <array>
        <string>armv7string>
    array>
    <key>UISupportedInterfaceOrientationskey>
    <array>
        <string>UIInterfaceOrientationPortraitstring>
        <string>UIInterfaceOrientationLandscapeLeftstring>
        <string>UIInterfaceOrientationLandscapeRightstring>
    array>
    <key>NSAppTransportSecuritykey>
    <dict>
        <key>NSAllowsArbitraryLoadskey>
        <true/>
    dict>
dict>
plist>

你可能感兴趣的:(IOS)