2015-10-14 91 views
2

我有一个由不同公司使用的应用程序。用户首先需要始终使用相同的base-url登录整个web服务。当他成功登录时,我从webservice获得一个base-url(带有htttps)。但是这个base-url对于每个公司都不相同。在代码中配置NSAppTransportSecurity

现在,当我开始我的IOS9应用程序,我登录并尝试调用Web服务具有不同的基URL,我得到这个错误:

Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorCodeKey=-9847, NSErrorFailingURLStringKey=https://81.82.219.213:8080/TechAppService/TechAppService.svc//authuser?login=***&password=*** 

我知道,我需要建立info.plist中的NSAppTransportSecurity字典。现在的问题是,我不知道如何在代码中设置它。

+0

你的问题不是,如何使用info.plist启用所有任意加载,但是如何在运行时配置特定于域的异常,是否正确? –

回答

2

第1步

选择info.plist并单击右键 - >去Source Code

enter image description here

步骤2

源代码打开为Key格式,在该密钥上添加以下内容在过去的

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

翼键,你可以看到样输出

enter image description here

步骤 - 3

它会自动在你的plist添加就像如下

enter image description here

1

其因有在iOS版SDK 9一些改变使用网络中的应用。您需要在info.plist文件中添加以下密钥。

Step 1:打开info.plist文件在您的项目。

Step 2:添加App Transport Security Settings关键。

Stpe 3:添加子键Allow Arbitrary Loads并将值设置为YES

这就是所有的详细信息read apple documentation

enter image description here

1

的Info.plist设置。欲了解更多信息请参阅给定图像中

enter image description here

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

粘贴到您的信息已结束的本。PLIST这将允许所有连接