确定iPhone上是否启用了飞行模式? [英] Determining if Airplane Mode is enabled on an iPhone?

查看:138
本文介绍了确定iPhone上是否启用了飞行模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:从某些版本的iOS 8(可能是8.3)开始,即使在飞行模式下也可以打开GPS硬件(即,即使在飞行模式下也可以获得GPS定位)。这使得这个问题没有实际意义。

UPDATE: As of some version of iOS 8 (8.3, maybe), GPS hardware can be turned on even in airplane mode (i.e., you can get GPS location even in airplane mode). This renders this question moot.

-

是否可以以编程方式确定iPhone是否在飞机上模式?我特别想知道它是否处于AirPlane模式,而不是拥有(或没有)网络连接。这个问题已被提出很多问题,但我见过的每个答案都提到了Apple的Reachability代码,以确定网络连接是否可用。

Is it possible to programatically determine if an iPhone is in Airplane Mode? I specifically want to know if it's in AirPlane Mode, as opposed to having (or not having) a network connection. This question has been asked a lot, but every answer I've seen has referred to Apple's Reachability code to determine if a network connection is available.

我正在写一个使用iPhone的GPS的应用程序。目前,如果启用了飞行模式并启动了我的应用程序,我的位置管理器对象仍然显示存在并且仍然显示为我提供了一个(缓存?)位置。状态栏中会显示小GPS图标,告诉我我的应用正在确定位置。

I'm writing an app that uses the iPhone's GPS. At the moment, if Airplane Mode is on and my app is launched, my location manager object still appears to exist and still appears to be giving me a (cached?) location. The little GPS icon appears in the status bar to let me know that my app is determining a location.

我想知道手机是否处于飞行模式以便我无法初始化位置管理器对象,我可以更改我的UI,向用户表明GPS功能不可用。

I want to know if the phone's in Airplane Mode so that I can not initialise the location manager object and I can change my UI to indicate to the user that GPS functionality is not available.

无论网络连接如何,显然都可以使用GPS功能,所以a缺乏网络连接让我觉得它是飞机模式的不良代理。在飞行模式下,我似乎没有得到任何特定错误(通过locationManager:didFailWithError),只是我假设的一般错误可能来自多个来源。

The GPS functionality can obviously be used regardless of network connectivity, so a lack of network connectivity strikes me as being a poor proxy for Airplane Mode. I don't appear to get any specific errors (through locationManager: didFailWithError) when in Airplane Mode, just a generic error that I'm assuming could come from a number of sources.

推荐答案

我的应用程序的类似要求,除了我事先知道它很可能用于无细胞信号环境(露营在偏远地区)和用户可能会将设备置于飞行模式以节省电池,而不会意识到它会关闭GPS。

Similar requirements for my app, except I knew in advance that it would most likely be used in a "no cell signal" environment (camping in a remote area) and that the user might put the device in airplane mode to conserve batteries, without realizing it shuts down GPS.

由于飞行模式不会导致didFailWithError,并且locationServicesEnabled返回yes,我设置一个60秒的计时器,如果在计时器到期之前没有返回GPS读数,我会向用户显示一条消息,告诉他们无法读取GPS数据,并建议他们检查飞机模式是否未启用,并且他们是确保他们能够清楚地看到天空。

Since airplane mode does not result in an didFailWithError, and locationServicesEnabled returns yes, I set a timer for 60 seconds, and if no GPS reading is returned before the timer expires, I display a message to the user telling them that GPS data can't be read, and suggest they check that airplane mode is not enabled, and that they ensure they have a clear view of the sky.

这篇关于确定iPhone上是否启用了飞行模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆