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
}
}
}
Post
Replies
Boosts
Views
Activity
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.
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?