URLSession dataTaskWithRequest

I have an app that searches for SSDP services on a local network and sends commands over http using URLSession. I know i need the new privacy entitlement to discover devices on the network so for now i have manually entered the device IP address that i want to send commands to but I'm getting the following time out error in the debug log when i send a request using URLSession dataTaskWithRequest

Task <529A4D4D-2249-4B51-9FF2-92207C5F5CDC>.<1> finished with error [-1001] Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={kCFStreamErrorCodeKey=-2102, NSUnderlyingError=0x283983240 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={kCFStreamErrorCodeKey=-2102, kCFStreamErrorDomainKey=4}}, NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <529A4D4D-2249-4B51-9FF2-92207C5F5CDC>.<1>, NSURLErrorRelatedURLSessionTaskErrorKey=(

    "LocalDataTask <529A4D4D-2249-4B51-9FF2-92207C5F5CDC>.<1>"

), NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=MANUAL
CONNECTIONIPADDRESS, NSErrorFailingURLKey=MANUALCONNECTIONIPADDRESS, kCFStreamErrorDomainKey=4}

Task <529A4D4D-2249-4B51-9FF2-92207C5F5CDC>.<1> HTTP load failed, 0/0 bytes (error code: -999 [1:89])

This works on previous version of iOS i'm just wondering if it could just be a bug or is there something I'm missing that's stopping me sending requests to the device on the local network. I've got the new Privacy Local Network Usage Description Key added to the info.Plist


Great that you've added the local network usage description! Are you getting a prompt to request access to the local network when this local network operation occurs?
No when i try and send the request i don't get any prompt to allow local network connections. When i wrote the post i was trying in on device, i have since tried on the simulator at it works but i still don't get the prompt.
The simulator uses your Mac’s network, which doesn’t restrict local network access. That’s expected to not see an error.

The fact that you get a timed-out error makes me wonder if the address is not actually going over the local network as you expect. Can you share an example URL you’re fetching? Is this IPv4 or IPv6?
This is an example of the IPv4 URL I'm sending over the local network (without the space) http:// 192.168.0.38:8060/keypress/Up

My mac, the device I'm sending requests to and my iPhone are all on the same network.

I've done a bit of experimenting creating a basic app with just a button to send the request once pressed. I wrote this is Swift my original project is written in Objective C

The first attempt i didn't include the privacy description key and i got the default prompt to allow network access. This is the code i ran and that worked.
Code Block
let session = URLSession.init(configuration: URLSessionConfiguration.default)
session.configuration.waitsForConnectivity = true
var request = URLRequest.init(url:URL.init(string:"http://192.168.0.38:8060/keypress/Up")!)
request.httpMethod = "POST"
request.addValue("0", forHTTPHeaderField:"Content-Length")
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
session.dataTask(with: request) { (data, responce, error) in
    print("");
}.resume()


I then deleted the app off my phone, added the usage description key to the info.Plist i didn't change anything else and installed the app again. Since then i haven't got the prompt and it's back to timing out on the request. I have looked in Settings > Privacy > Local Network and the test app isn't showing up in the settings. I even tried removing the description key but still no luck.


That’s really interesting. Any chance you can capture some logs via these instructions and file those, along with your sample, via Feedback Assistant (post the number here for reference)?
Hi, I've captured the logs and submitted them to the Feedback Assistant with the test app i created. Ref No: FB7790409
have you found any solution for -1001 errors. I have been facing similar errors for some time and even after implementing retry logic. it keeps failing
URLSession dataTaskWithRequest
 
 
Q