We're experiencing an issue with Local Network Permission. When trying to connect to a socket, the Local Network Permission alert pops up. To trigger the permission request at the start of the app, we used the following code to ask for permission and receive a callback on whether it's granted. However, this approach doesn't always trigger the permission alert, or it gets automatically dismissed after 30 seconds, only to reappear later. What could be causing this inconsistent behavior?
func checkLocalNetworkPermission(_ completed: Optional<(Bool) -> Void> = .none) {
DispatchQueue.global(qos: .userInitiated).async {
let hostName = ProcessInfo.processInfo.hostName
let isGranted = hostName.contains(".local")
if let completed {
DispatchQueue.main.async {
completed(isGranted)
}
}
}
}
I generally recommend that you not explicitly trigger the local network privacy alert, but rather do it organically by performing a local network operation. However, if you must trigger it explicitly for some reason, use the code in TN3179 Understanding local network privacy.
Oh, and TN3179 is chock full of local network privacy hints and tips. Read the whole thing carefully.
Why would you do that? It’s generally best to trigger privacy alerts when the user performs an operation that’s obviously associated with the alert. If you trigger a bunch of privacy alerts on app startup, most users are just gonna click Deny, Deny, and Deny.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"