Reachability airplane mode (3G) vs. Wifi
Asked Answered
G

2

0

I know the Reachability code will provide if the phone has access to Wifi or 3G network.

However, if the phone has 3G on and Wifi, the Reachability code defaults to saying the phone has Wifi on and I can't detect if 3G network is enabled or not (airplane mode on or off).

I need to find out specifically if 3G mode is on or off when Wifi is also on.

Here is the code:

Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];

NetworkStatus status = [reachability currentReachabilityStatus];

NSLog(@"status: %u", status);

if(status == NotReachable)  //status = 0
{
    //No internet
    NSLog(@"nothing is reachable");
}
if (status == ReachableViaWiFi) //status = 1
{
    //WiFi
    NSLog(@"Wifi is available");
}
if (status == ReachableViaWWAN) //status = 2
{
    //3G
    NSLog(@"3G is available");
}
NSLog(@"%@", s);

Basically status is returning 1 even if the 3G is on as well as Wifi.

Is this possible?

Gratia answered 26/10, 2012 at 22:9 Comment(3)
If the phone has access to both 3G and Wi-Fi, it will always connect to the Wi-Fi network instead of choosing the 3G, so it might not make sense to detect that fact.Wooded
I know what you're saying, however, in my case, unfortunately it has to detect if 3G is enabled for the app I'm developing.Gratia
check this link it may be useful for you #11961313Somnifacient
G
1

Currently there is no way to do this on the iPhone following Apple guidelines and without using their private API.

Gratia answered 30/11, 2012 at 23:2 Comment(0)
M
1

Update: It seems like it is not possible as of now. However you can try the following codes, just in case if it helps.

Code1: Just a thought. Haven't tried this.

if (status == ReachableViaWiFi) //status = 1
{
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]]) {
        NSLog(@"Wifi and 3G are available");
    } else {
        NSLog(@"Wifi is available, but 3G is not available");
    }
}

Code 2:

For internal apps you can use this approach as mentioned here,

Note: This uses private API, so your app will be rejected if you use it in appstore app.

Copy paste the below contents into RadioPreferences.h

@protocol RadiosPreferencesDelegate
-(void)airplaneModeChanged;
@end


@interface RadiosPreferences : NSObject
{
    struct __SCPreferences *_prefs;
    int _applySkipCount;
    id <RadiosPreferencesDelegate> _delegate;
    BOOL _isCachedAirplaneModeValid;
    BOOL _cachedAirplaneMode;
    BOOL notifyForExternalChangeOnly;
}

- (id)init;
- (void)dealloc;
@property(nonatomic) BOOL airplaneMode;
- (void)refresh;
- (void)initializeSCPrefs:(id)arg1;
- (void)notifyTarget:(unsigned int)arg1;
- (void)synchronize;
- (void *)getValueForKey:(id)arg1;
- (void)setValue:(void *)arg1 forKey:(id)arg2;
@property(nonatomic) BOOL notifyForExternalChangeOnly; // @synthesize notifyForExternalChangeOnly;
@property(nonatomic) id <RadiosPreferencesDelegate> delegate; // @synthesize delegate=_delegate;

@end 

Then try as below.

id rp = [[RadiosPreferences alloc] init];
BOOL status = [rp airplaneMode];
return status;
Mutinous answered 26/10, 2012 at 22:37 Comment(4)
So I tried this but canOpenURL doesn't change anything. It still thinks 3G is also available when it is in airplane mode. Then I also tried openURL:[NSURL URLWithString:@"tel://1234567"] but this time, it'll show a message saying you must disable airplane mode to make a phone call. Just like the normal msg you get when you try to make a phone call in airplane modeGratia
See https://mcmap.net/q/299667/-detect-airplane-mode-on-ios, #1405151, blog.sallarp.com/iphone-flight-mode-detection-with-code, and discussions.apple.com/thread/1761374?start=0&tstart=0Mutinous
Thank you so much for the RadiosPreferences edit and all your other help, though the RadiosPreferences didn't work, it's always returning status as NO (false). I also found this: discussions.apple.com/thread/1761374?start=0&tstart=0 it doesn't make any sense that Apple doesn't allow developers to check for this simple flag.Gratia
Also, this app will needs to be on the AppStore once it is done, so that doesn't help eitherGratia
G
1

Currently there is no way to do this on the iPhone following Apple guidelines and without using their private API.

Gratia answered 30/11, 2012 at 23:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.