c19354837/react-native-system-setting

isAirplaneEnabled always return true

DCKT opened this issue ยท 9 comments

DCKT commented

Hello,

On iOS only , isAirplaneEnabled() always return true.
It works perfectly on Android. Maybe a config issue ?

Thanks ๐Ÿ˜„

Have you run the example ?

It works fine in my iPhone 7 plus (iOS 11.3.1), how about your test device?

DCKT commented

Hi @c19354837

I does compile on the simulator but not on my test device, I have this error :
capture d ecran 2018-06-04 a 10 47 11

EDIT : I'm on the latest XCode version I think (9.3.1) & my test device is an iPhone 5C (iOS 10.3.3)

Some APIs may not work well in simulator, and you should test in the physical device.

The error is React-Native's bug, see this PR

I just change the code to:

static NSString *RCTCacheKeyForImage(NSString *imageTag, CGSize size, CGFloat scale,
                                     RCTResizeMode resizeMode, NSString *responseDate)
{
    return [NSString stringWithFormat:@"%@|%g|%g|%g|%lld|%@",
            imageTag, size.width, size.height, scale, (long long)resizeMode, responseDate];
}
DCKT commented

Yes I succeeded to make it compile and I have the same behavior : here is a screenshot

img_0013

As you can see, the airplane mode is not enabled and it says it's "On". Is it normal, when I want to toggle the switch it send me to the bluetooth settings ?

It's really strange.

I'll try to find a iPhone with iOS 10. It may take some time.

For some iOS's limits, this lib just opens the Settings app whit the last page that you open.

DCKT commented

Thanks for your quick answers ๐Ÿ˜„

I think I get it.

I get airplane's status by:

NSString * radio = [[CTTelephonyNetworkInfo alloc] init].currentRadioAccessTechnology;
bool isEnabled = radio == nil;

and the currentRadioAccessTechnology means The current radio access technology the device is registered with.

Normally, if your device has no SIM, isAirplaneEnabled() always return true.

There is no official API which can get airplane mode directly.

Here are some discussions.


And

Is it normal, when I want to toggle the switch it send me to the bluetooth settings ?

It's a bug in iOS 10, and it's normal in iOS 11 for some system limits. Next version will fix it.

DCKT commented

Hi @c19354837

Thanks a lot for your investigations ! I will find a device with a SIM card.
I think you can add this to the README ๐Ÿ˜„

V1.4.6 is available.

fix bug: switchAirplane() will open Bluetooth Setting Page for iOS.

Also I update the README & API.

Thanks for your work.