If internet is not reachable, is it possible to programmatically distinguish between the following permission cases?
- A case where user has denied permissions to use Data for the app.
- A case where user has granted permissions to use Data, but phone is in Flight Mode (or has no SIM/WiFi at all).
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)
}