How to check if iPhone is in Airplane Mode with Sw

2019-02-28 03:55发布

I'd like to check whether flight mode is activated. If so, I need to show a warning message.

How can I check whether flight (airplane) mode is active using Swift?

3条回答
We Are One
2楼-- · 2019-02-28 04:13

The easiest way is to let iOS done it for you.

to go Info.plist -> add this **Application uses Wi-Fi (Boolean) YES*

To test: Kill your app -> turn on airplane mode -> open ur app: you should be able to see alert within the app. Tested on iPhone iOS9

in Xcode 7

查看更多
该账号已被封号
3楼-- · 2019-02-28 04:19

If you are using Location Services, they should return with an error code of 1009 by presenting the following in log:

Geocode error: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline."

If you check for a return code of -1009, you can recognize the user as offline and follow through accordingly.

查看更多
倾城 Initia
4楼-- · 2019-02-28 04:39

As far as I know you can't -- or you can't using public API. My suggestion would be to call required devices and set corresponding notifications. If you really need to know if its flight mode, maybe you can do that with calling 3G, GPS, Wi-Fi etc. and check if every one is off.

I saw another suggestion with taking an in-app screenshot and checking for orange airplane ( does top contains orange part ).

Drawbacks are present for both, My suggestion is bad since your devices could be off for other, not related reasons.

Good luck.

查看更多
登录 后发表回答