TIC TCP Conn Error starting Swift project on my phone

I am new to Swift. I created a simple application that works great on a simulator. I run the same on my device (iPhone 6s with iOS 11.0.2) and cannot connect to the server.

getting these errors:

2017-10-26 18:16:02.489134-0400 myproj[1451:206438] TIC TCP Conn Failed [1:0x1c0176800]: 1:61 Err(61) 2017-10-26 18:16:02.489771-0400 myproj[1451:206438] Task <0C30ADDC-4A0E-4815-A701-2EF0A7CF5F04>.<1> HTTP load failed (error code: -1004 [1:61]) 2017-10-26 18:16:02.490293-0400 myproj[1451:206440] Task <0C30ADDC-4A0E-4815-A701-2EF0A7CF5F04>.<1> finished with error - code: -1004 

Please help me understand this error.

EDIT:

Here is the code calling the server:

 func postRequest(postData: NSDictionary, postHeaders: NSDictionary, endPoint: String, onComplete: @escaping ((NSDictionary)->Void), callbackParams: NSDictionary = NSMutableDictionary()) { let url:URL = baseUrl.appendingPathComponent(endPoint) let session = URLSession.shared let request = NSMutableURLRequest(url: url) request.httpMethod = "POST" request.cachePolicy = NSURLRequest.CachePolicy.reloadIgnoringCacheData var paramString = "" for (key, value) in postData{ paramString = paramString + (key as! String) + "=" + (value as! String) + "&" } request.allHTTPHeaderFields = postHeaders as? [String : String] request.httpBody = paramString.data(using: String.Encoding.utf8) let task = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in guard let _:Data = data, let _:URLResponse = response , error == nil else { return} let json: Any? do { json = try JSONSerialization.jsonObject(with: data!, options: []) } catch { return } var serverResponse = json as? NSDictionary DispatchQueue.main.async{ for (key, value) in serverResponse!{ callbackParams.setValue(value, forKey: key as! String) } onComplete(callbackParams) } }) task.resume() } 

EDIT:

Adding a screenshot from info.plist, I set the Allow arbitrary loads to True, as indicated in other posts, but didn’t solve Thanks!

+8
ios swift
source share
4 answers

Error -1004 is equal to URLError.cannotConnectToHost . For some reason, it cannot connect to the server.

In the comments, you indicate that the URL is http://127.0.0.1 . This is localhost , the current computer. If you use this URL on a physical phone, it will look for a web server on the phone. Lol It works on the simulator because the simulator is your computer, localhost .

You need a URL that your iPhone can resolve on the computer running your web service. For example, find out what IP address is for the computer running the web service on the local network, make sure your iPhone is connected to Wi-Fi on the same network, and then use this unique IP number for your computer on the local network ( most likely 192.168.0.x).

+14
source share

I had the same issue when I sent / received socket messages! I use Socket.io and Firebase for push, and the error was on the node.js server. The mistake was that the mongoose version was outdated . Whenever this error occurs on iOS End, ask node.js the backend command to look for red logs. They will surely find the problem that caused this error when using the interface. Hope this helps!

0
source share

In my case, I do not change the IP address of the local host.

 Example : @"http://Localhost/Host name/index.pnp/apiname?"; 

I originally use the above URL, so I have the same error ...

Later I changed to Localhost to 190.177.0.22

 Example : @"http://190.177.0.22/Host name/index.pnp/apiname?"; 
0
source share

Another example of a corner, if you use something like ngrok and it still does not work, the phone is not connected to the network of the service provider or Wi-Fi.

In my case, my main phone worked as a second idle phone.

0
source share

All Articles