2015-10-14 83 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這將允許所有連接