Is it possible to differentiate whether user has no signal from carrier's mobile internet or purposefully has Airplane mode enabled?
I want to disable some features inside my app if user has Airplane mode enable. At the same time, I want to keep these same features enabled if the device simply do not have service from carrier at that moment.
platform :ios, '11.0'
Following block code with Objective C was found in a StackOverFlow post and it is helpfull but it either lack of signal from carrier or airplane mode returns as ConnectionTypeNone
.
typedef enum {
ConnectionTypeUnknown,
ConnectionTypeNone,
ConnectionType3G,
ConnectionTypeWiFi
} ConnectionType;
+ (ConnectionType)connectionType
{
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, "8.8.8.8");
SCNetworkReachabilityFlags flags;
BOOL success = SCNetworkReachabilityGetFlags(reachability, &flags);
CFRelease(reachability);
if (!success) {
return ConnectionTypeUnknown;
}
BOOL isReachable = ((flags & kSCNetworkReachabilityFlagsReachable) != 0);
BOOL needsConnection = ((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0);
BOOL isNetworkReachable = (isReachable && !needsConnection);
if (!isNetworkReachable) {
return ConnectionTypeNone;
} else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
return ConnectionType3G;
} else {
return ConnectionTypeWiFi;
}
}