I’m developing an iOS app using SwiftUI whose data records include numerous web URL addresses. I’m developing a MacOS utility app that I’ll be using to edit and maintain the data in my iOS app.
Because there will be a lot of URL web links included in the data, I’m trying to create an automated audit function in my MacOS utility app that I can use periodically to go through the data records and test each one of the links to find broken/outdated links that need updating or removal.
However, every time I try to test a link (even valid ones), I always get an error.
I’ve added the following to the pList for the macOS utility app.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Here is a simplified function to test the validity of a single, valid URL (for this test I used the google URL):
func testGetUrlRequest()
{
let url = URL(string: "https://www.google.com/")!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
print("The response is : ",String(data: data, encoding: .utf8)!)
//print(NSString(data: data, encoding: String.Encoding.utf8.rawValue) as Any)
}
task.resume()
}
When I run this code, the following response is printed to the console:
Request failed with error: A server with the specified hostname could not be found. Error details: Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x6000017d1fb0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_kCFStreamErrorDomainKey=10, _kCFStreamErrorCodeKey=-72000, _NSURLErrorNWResolutionReportKey=Resolved 0 endpoints in 1ms using unknown from query, _NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <4DD76B44-1F80-45BD-A2F6-AF9EFAF9B921>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <4DD76B44-1F80-45BD-A2F6-AF9EFAF9B921>.<1>" ), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://www.google.com/, NSErrorFailingURLKey=https://www.google.com/, _kCFStreamErrorDomainKey=10}
Given the "A server with the specified hostname could not be found.” error for an obviously viable URL, there must be another problem.
Since this is my own development utility app, I’m just running it on my MacBook from Xcode. Could that be part of the issue?
Any other ideas?
But you have failed to report to us the part of the error message that says (and thus gives the answer):
The sandbox profile for this process is preventing communication with network content filters. Please modify the sandbox profile to allow access to the com.apple.nesessionmanager.content-filter Mach service
In other words: