Local Network Privacy Prompt is not received from an XCTestCase

Originator:ncreated
Number:rdar://FB8983382 Date Originated:Jan 28, 2021
Status:Potential fix identified - In Xcode 13 Resolved:
Product:Xcode Product Version:12.3 (12C33)
Classification: Reproducible:Always
 
I'm trying to make a network call from `XCTestCase` to the server running in my local network (http://192.168.0.94:8000). Even though I added the `NSLocalNetworkUsageDescription` value to my UITests' target `Info.plist`, the prompt is not received when running the test on my iPhone and the request results with `Error Domain=kCFErrorDomainCFNetwork Code=-1009` .

Adding `NSLocalNetworkUsageDescription` value to the target of the app being tested and making the same request from this app works as expected: I receive the prompt, confirm it and the network request can be send successfully.

Steps to reproduce:
1. Create plain "Single View" application with UITests target.
2. Set `NSLocalNetworkUsageDescription` value in UITest targets' `Info.plist`.
3. Send an HTTP request to the server running in local network from within the test in `XCTestCase`, using `URLSession.dataTask`.
4. Run it on a device connected to the same local network.

Expected behaviour:
The prompt should appear. Once agreed, the request should be send. The agreement should be cached, so for each next try the prompt should be skipped. The request should result with actual server response.

Actual behaviour:
The prompt doesn't appear. The request does not hit the server and results with error of this kind:
```
Error Domain=NSURLErrorDomain Code=-1009 "The internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x2833f34b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <D206B326-1820-43CA-A54C-5B470B4F1A79>.<2>, _NSURLErrorRelatedURLSessionTaskErrorKey=("LocalDataTask <D206B326-1820-43CA-A54C-5B470B4F1A79>.<2>"), NSLocalizedDescription=The internet connection appears to be offline., NSErrorFailingURLStringKey= http://192.168.0.94:8000, NSErrorFailingURLKey= http://192.168.0.94:8000, _kCFStreamErrorDomainKey=1}
```

Environment:
- Xcode 12.3 (12C33)
- iPhone X with iOS 14.3 (18C66)

Comments

I've tested with Xcode 13.2 and iOS 15.2 and the request still fails with the same error. Any updates on this issue?

Apple updated the status to "Potential fix identified - In Xcode 13". I confirm - it works now. Closing this feedback.

Hey @ncreated! How were you able to make this work?


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!