How can I detect if the phone is in airplane mode? (It's not enough to detect there is no internet connection, I have to be able to distinguish these 2 cases)
Try using SCNetworkReachabilityGetFlags
(SystemConfiguration framework). If the flags variable handed back is 0 and the return value is YES, airplane mode is turned on.
Check out Apple's Reachability classes.
You can add the SBUsesNetwork boolean flag set to true in your Info.plist to display the popup used in Mail when in Airplane Mode.
Since iOS 12 and the Network Framework it's somehow possible to detect if airplane mode is active.
import Network
let monitor = NWPathMonitor()
monitor.pathUpdateHandler = { path in
if path.availableInterfaces.count == 0 { print("Flight mode") }
print(path.availableInterfaces)
}
let queue = DispatchQueue.global(qos: .background)
monitor.start(queue: queue)
path.availableInterfaces
is returning an array. For example [en0, pdp_ip0]
. If no interface is available is probably on flight mode.
WARNING
If airplane mode and wifi is active then path.availableInterfaces
is not empty, because it's returning [en0]
Flight mode
and then crash, since you are printing the path.availableInterfaces
array when it is empty. I think you should put the second print into the else
statement. –
Intravasation For jailbroken tweaks/apps:
@interface SBTelephonyManager : NSObject
+(id)sharedTelephonyManager;
-(BOOL)isInAirplaneMode;
@end
...
bool isInAirplaneMode = [[%c(SBTelephonyManager) sharedTelephonyManager] isInAirplaneMode];
We can not get this information without using private libraries. Here is some code but it will not work when carrier signal is not available.
UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
NSString *dataNetworkItemView = nil;
for (id subview in subviews) {
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView") class]]) {
dataNetworkItemView = subview;
break;
}
}
double signalStrength = [[dataNetworkItemView valueForKey:@"signalStrengthRaw"] intValue];
if (signalStrength > 0) {
NSLog(@"Airplane mode or NO signal");
}
else{
NSLog(@"signal available");
}
© 2022 - 2024 — McMap. All rights reserved.