2017-08-25 43 views
0

所以我有一個簡單的main.swiftEXC_BAD_ACCESS上Alamofire Github的例子

import Foundation 
import Alamofire 

Alamofire.request("https://httpbin.org/get").responseJSON { response in 
    print("Request: \(String(describing: response.request))") // original url request 
    print("Response: \(String(describing: response.response))") // http url response 
    print("Result: \(response.result)") // response serialization result 

    if let json = response.result.value { 
    print("JSON: \(json)") // serialized json response 
    } 

    if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) { 
    print("Data: \(utf8Text)") // original server data as UTF8 string 
    } 
} 

當我運行這一點,得到了「程序,退出代碼結束:0」,僅此而已。 我把斷點

Alamofire.request("https://httpbin.org/get").responseJSON { response in 

,看到這一點 - 在 「responseJSON」 方法 EXC_BAD_ACCESS

問題。我做錯了什麼?來自Alamofire Github的簡單例子。

+0

誰能給我解釋一下嗎?我只添加了這個代碼「RunLoop.current.run()」,它工作正常 – doublench

回答

-1

請在info.plist中

<dict> 
    <key>NSAppTransportSecurity</key> 
    <dict> 
     <key>NSExceptionDomains</key> 
     <dict> 
      <key>example.com</key> 
      <dict> 
       <key>NSExceptionAllowsInsecureHTTPLoads</key> 
       <true/> 
       <key>NSExceptionRequiresForwardSecrecy</key> 
       <false/> 
       <key>NSIncludesSubdomains</key> 
       <true/> 
       <!-- Optional: Specify minimum TLS version --> 
       <key>NSTemporaryExceptionMinimumTLSVersion</key> 
       <string>TLSv1.2</string> 
      </dict> 
     </dict> 
    </dict> 
</dict> 

添加這些線路也請把基本URL

+0

我沒有「info.plist」。 – doublench

+0

缺乏應用程序傳輸安全性不會使程序以「程序以退出代碼結尾:0」結束。 – Moritz