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)!) } } }
Question: Q: what is NSURLErrorDomain: -1003 Answer: A: 1003 is NSURLErrorCannotFindHost meaning that the host name for a URL couldn't be resolved.
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.
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.
Slight improvement over Udaya Sri's answer:
Explicitly allow for network connections while keeping the sandbox enabled like so:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With