I am using Xcode beta6. I created an application that has the Downloader class, and this is the Downloader class:
class Downloader : NSObject { private var _connection : NSURLConnection? private var _downloadedData: NSMutableData? func getDataFromURLString(urlToRequest: String!, aType: DownloadedDataType) { _downloadedData = NSMutableData() var request : NSMutableURLRequest = NSMutableURLRequest(URL: NSURL(string: urlToRequest), cachePolicy: .ReloadIgnoringLocalCacheData, timeoutInterval: 20.0) request.setValue("", forHTTPHeaderField: "Accept-Encoding") self._connection = NSURLConnection(request: request, delegate:self) } func connection(connection: NSURLConnection!, didReceiveResponse response: NSURLResponse!) { println("Data expected size: \(response.expectedContentLength)") } func connectionDidFinishLoading(connection: NSURLConnection!) { println("finished") } func connection(connection: NSURLConnection!, didFailWithError error: NSError!) { println("error: \(error)") } func connection(connection: NSURLConnection!, didReceiveData data: NSData!) { _downloadedData?.appendData(data) } }
This class works well and gets the correct JSON result when the server is on the network with a LAN cable, but when this server is connected to the same network via WiFi, I get this error from the iOS device:
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost."
But this is really strange, because if I insert the json path into the browser, I see json. So only on iOS devices I canโt cope, but I donโt know what I have to fix. Can anybody help me?
So, if my Mac mini, which I use for development, is on Lan, and the server on Lan, everything works fine. But when my Mac mini is on WiFi and my server is on Wi-Fi, I get this error ...
ios swift nsurlconnection nsurl nsurlconnectiondelegate
David
source share