2017-09-19 65 views
0

在我的XCTests中,我連接到http(不是https)服務器。這在我的產品應用程序中不會發生。有沒有辦法,我只能將此例外:ATS(應用程序傳輸安全)僅用於XCTests的例外

<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSExceptionDomains</key> 
    <dict> 
     <key>echo.jsontest.com</key> 
     <dict> 
      <key>NSExceptionAllowsInsecureHTTPLoads</key> 
      <true/> 
     </dict> 
    </dict> 
</dict> 

的測試,而不是主要的應用程序?

我已經試過把這個放在Info.plist中進行測試,但是確實會生成,但是不會提供異常。

回答

0

您需要添加NSIncludesSubdomains密鑰並將其設置爲true。

<key>NSAppTransportSecurity</key> 
    <dict> 
     <key>NSAllowsArbitraryLoads</key> 
     <false/> 
     <key>NSExceptionDomains</key> 
     <dict> 
      <key>echo.jsontest.com</key> 
      <dict> 
       <key>NSExceptionAllowsInsecureHTTPLoads</key> 
       <true/> 
       <key>NSIncludesSubdomains</key> 
       <true/> 
      </dict> 
     </dict> 
    </dict> 
+0

如果我用你的價值觀進行測試的.plist或者,如果我只是NSIncludesSubdomains部件添加到我的測試的.plist,這是行不通的。我沒有得到例外。 –

+0

它需要添加到應用程序的Info.plist中,因爲即使在測試下,它也會發出請求。 – Oletha

+0

這不是我的問題。我的問題是:只適用於XCTest的。如果我將該例外置於應用程序的.plist中,則不會僅用於XCTest。 –

相關問題