I use Xcode beta6. I created an app which have a 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 get the right JSON result when the server is on the network with LAN cable but when this server 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 Its really weird because if I paste the json path to the browser I see the json.. So only on iOS devices cant handle, but I dont know what I should fix.. Can anyone help me?
So If my Mac mini what I use to develop is on Lan, and the Server is on Lan, everything works fine. But when my Mac mini is on WiFi and my server is on Wifi I get this error...