If internet is not reachable, is it possible to programmatically distinguish between the following permission cases?
I'd like to read those Wireless Data permissions to distinguish the above cases for more friendly error messages (i.e. in one case I would recommend to verify Permissions, and in the other case I would recommend to check Flight Mode)
All I could find is to get internet reachability, based on How to use SCNetworkReachability in Swift, but it doesn't know about actual permissions:
import SystemConfiguration
@available(iOS 9.0, macOS 10.11, *)
static func internetConnectionIsReachable() -> Bool {
var zeroAddress = sockaddr_in6()
zeroAddress.sin6_len = UInt8(MemoryLayout<sockaddr_in6>.size)
zeroAddress.sin6_family = sa_family_t(AF_INET6)
guard let reachability = withUnsafePointer(to: &zeroAddress, {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
SCNetworkReachabilityCreateWithAddress(nil, $0)
}
}) else {
return false
}
var flags: SCNetworkReachabilityFlags = []
guard SCNetworkReachabilityGetFlags(reachability, &flags) else {
return false
}
return flags.contains(.reachable)
}
In a word, you probably can't distinguish these cases, and you probably shouldn't want to. Apple doesn't even really want you to use reachability. Their view is: Yours not to reason why, yours but to do (i.e. try to use the network) or die (i.e. fail). Fail gracefully if you're going to fail, and you've done your job.
As a general rule, you cannot read permissions directly. You can only determine capabilities (by which I mean "it fails when you try to do something"), which are sometimes set in ways other than user-controlable permissions, such as parental controls or restrictions imposed by an enterprise cert. You may get lucky here and there's a way, but my expectation would be 'no'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With