Check if Local Network access is granted

Hello, I was referring to the post - https://developer.apple.com/forums/thread/663769 to determine if my app has been granted access to Local Network or not. I am starting an NWConnection for a local network address and checking if the currentPath?.unsatisfiedReason == .localNetworkDenied. This is not working as expected.

Even when I accept the local network permission prompt, I still get the unsatisfied reason as .localNetworkDenied. I have also tried turning off/on the permission toggle from the settings app. I have also checked this with the 2nd method in the above post about using pathUpdateHandler and getting the same results. I am using an iOS 17.4.1 device.

Is this method reliable? Is there some other method/api that I can use to check for local network access in my app?

On checking further, the app's functionality based on Local Network access is also broken. I use this permission in my app to make a request to a local network address. The request is failing with error code - NSURLErrorNotConnectedToInternet even though the permission toggle is on. The issue gets resolved on restarting the device. Can someone please help with what might be causing this issue?

The issue gets resolved on restarting the device.

Does the problem then come back at some point?

In general, your app’s local network privacy state shouldn’t be affected by restarts. If it is, something weird is afoot.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The issue comes back sometimes when I re-install the app (uninstall and then install). Here is a code snippet of the method I use to check if the permission is denied:

let host = NWEndpoint.Host(someLocalNetworkAddress) let port = NWEndpoint.Port(rawValue: UInt16(80))! self.connection = NWConnection(host: host, port: port, using: .tcp) self.connection?.stateUpdateHandler = { latestState in if #available(iOS 14.2, *) { if self.connection?.currentPath == nil { return } else if self.connection?.currentPath?.unsatisfiedReason == .localNetworkDenied { // permission is not granted } else { // permission is granted } } }

When the issue occurs, I always get the currentPath as unsatisfied and the unsatisfiedReason as localNetworkDenied even though the permission toggle is on for my app in the settings app.

Reposting code block:

let port = NWEndpoint.Port(rawValue: UInt16(80))!
self.connection = NWConnection(host: host, port: port, using: .tcp)
self.connection?.stateUpdateHandler = { latestState in
    if #available(iOS 14.2, *) {
        if self.connection?.currentPath == nil {
            return
        } else if self.connection?.currentPath?.unsatisfiedReason == .localNetworkDenied {
            // permission is not granted
        } else {
            // permission is granted
        }
    }
}

The issue comes back sometimes when I re-install the app (uninstall and then install).

OK.

Something weird is definitely going on here. When I tested this myself yesterday I hit a situation where my app — a new test app, one that my device had never seen — was able to access the local network without any local network alert! And then, based on your tip about restarting, I restarted my device and things started behaving again.

My recommendation here:

  1. Following the Network Diagnostics for iOS instructions on our Bug Reporting > Profiles and Logs page to enable extra network debugging.

  2. Restart your device.

  3. Continue testing with this stuff.

  4. As soon as you notice weird behaviour, trigger a sysdiagnose log.

  5. Put that into a bug report.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Check if Local Network access is granted
 
 
Q