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

swift 开发

        URLSession.shared.dataTask(with: URLRequest(url: url)){data, response, error in
            // Handle errors
            if let error = error {
            print("Error dataTask: \(error)")
            return
            }

            // Handle the response
            if let data = data {
                do {
                    // Parse JSON data
                    let json = try JSONSerialization.jsonObject(with: data, options: [])
                    print("JSON Response: \(json)")
                } catch {
                    print("Error parsing JSON: \(error)")
                }
            }
            
        }.resume()

  Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found.  报错

  1. Open the Xcode project.
  2. In the Project Navigator, select the project target.
  3. Navigate to the Signing & Capabilities tab.
  4. Under the App Sandbox section, enable the following Network options by checking the boxes:
    • Incoming Connections (Server)
    • Outgoing Connections (Client)

  来源: https://support.auth0.com/center/s/article/Resolving-A-server-with-the-specified-hostname-could-not-be-found-Error-with-Auth0-Swift-SDK-in-Xcode

 

posted on 2026-06-10 14:28  少杨  阅读(3)  评论(0)    收藏  举报