我正在用Swift構建OS X Today窗口小部件。這應該通過HTTPS調用JSON API並顯示結果。到現在爲止還挺好。OS X Widget模擬器中無網絡連接(HTTPS)
但是,當我在Widget Simulator中運行小部件時,總是收到錯誤「無法找到指定主機名的服務器」。該URL是正確的,它在我在命令行上捲曲時起作用。看起來Widget Simulator沒有提供適當的DNS查找或完全阻止https流量。
我正在使用Alamofire,但我也嘗試過使用NSURLSession。同樣的結果。
let url = NSURL(string: "https://httpbin.org/get")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
debugPrint(error)
}
task.resume()
,導致:
Optional(
Error
Domain=NSURLErrorDomain
Code=-1003 "A server with the specified hostname could not be found."
UserInfo={
NSUnderlyingError=0x7fe1f3e341a0
ErrorDomain=kCFErrorDomainCFNetwork
Code=-1003 "(null)"
UserInfo={
_kCFStreamErrorCodeKey=-72000,
_kCFStreamErrorDomainKey=10}
},
NSErrorFailingURLStringKey=https://httpbin.org/get,
NSErrorFailingURLKey=https://httpbin.org/get,
_kCFStreamErrorDomainKey=10,
_kCFStreamErrorCodeKey=-72000,
NSLocalizedDescription=A server with the specified hostname could not be found.
}
)
的Widget模擬器應該能夠做到外連接,是嗎?