Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Error Code=-1003 "A server with the specified hostname could not be found."

I am trying to load image from URL on the iphone, image is there and I can open it in safari with same link, but not in the app:

Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname  could not be found." UserInfo={NSUnderlyingError=0x17024f810  {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)"  UserInfo={_kCFStreamErrorCodeKey=50331647, _kCFStreamErrorDomainKey=6147928288}},  NSErrorFailingURLStringKey=https://........, NSErrorFailingURLKey=https://......... 

Code of request:

func downloadImage(userEmail: String, onCompletion: @escaping (UIImage) -> Void) {     print("Download Started")     let route = "\(baseURL as String)\(userEmail as String)\(baseURLparameters as String)"     let url = URL(string: route)      getDataFromUrl(url: url!) { (data, response, error)  in         guard let data = data, error == nil else {             print("===failed:", error ?? "dunno")             print("===url:", url?.absoluteString ?? "dunno")             return         }         print(response?.suggestedFilename ?? url!.lastPathComponent )         print("Download Finished")         DispatchQueue.main.async() { () -> Void in             onCompletion(UIImage(data: data)!)         }     }  } 
like image 948
Async- Avatar asked Mar 24 '17 10:03

Async-


People also ask

What NSURLErrorDomain 1003?

Question: Q: what is NSURLErrorDomain: -1003 Answer: A: 1003 is NSURLErrorCannotFindHost meaning that the host name for a URL couldn't be resolved.

What does a server with the specified host name could not be found mean?

One common phrase Apple users may see as an error message includes the term: "A server with the specified hostname could not be found." This indicates that the server name in question is either misspelled or no longer available. To change a server name on iOS devices, users can go directly to their phone settings.


2 Answers

In my case, when I connect the signing team account to Xcode it was automatically switch on the App Sandbox in Capabilities. When I turn off it I could do server request without any problems.

enter image description here

like image 60
Udaya Sri Avatar answered Sep 17 '22 22:09

Udaya Sri


Slight improvement over Udaya Sri's answer:

Explicitly allow for network connections while keeping the sandbox enabled like so:

enter image description here

like image 24
de. Avatar answered Sep 18 '22 22:09

de.