I wanted to know how to verify if a user has given my application access to the local network. After some experimenting I came up with this solution.
I wrote up this class that can be used if you're not on iOS 14.2.
- This class will prompt user for permission to access local network (first time).
- Verify existing permission state if already denied/granted.
Just remember this instance has to be kept alive so if you are using this in a function call within another class you need to keep the instance alive outside of the scope of the calling function. You will also need the network multicasting entitlement under certain circumstances.
Declare outside the scope of the function in order to keep alive. Just remember to set to nil once you're done if the whole calling class isn't being deallocated later in order to unsubscribe to notifications.
Can be used like this: