How to be notified when iPhone enters airplane mode? - iphone

Is there a way for my app to be notified when the device enters (and leaves) airplane mode?

You can use Apple's Reachability code to see if a user has network access when they open your app or similar.
There is however no notification/trigger which your app can intercept/run arbitary code when a user enters or leaves airplane mode in the Settings.

Related

How to prevent the CoreBluetooth library from prompting to turn-on an iOS device's bluetooth?

I would like to detect whether an iOS device has Bluetooth enabled so that I can prevent the CoreBluetooth library from prompting the app user to enable it. I am NOT looking to check the state of the CBCentralManager; I just want to prevent the blue popup box so that it doesn't annoy my users.
You can't use CoreBluetooth in your app without the dialog. So if you want to prevent it all together, you can't.
If you just want to prevent if if they have Bluetooth off, then checking the state of CBCentralManager first is the right approach (ie check to see if it == CBCentralManagerStatePoweredOff).

Is it possible to flash a flashlight in iPhone when application is background mode?

Is it possible to flash a flashlight in iPhone when application is background mode?
Please give some suitable suggestion.
Already given the answer similar of your this question, pls see this link at once
Iphone flashlight not working while app is in background
This is a normal behavior.
Apple's sandboxing will not allow you to keep the flash on while your app is in the background.
There is no workaround unless we are talking about a jailbroken app.
Edit:
Apple is very strict on it's system's APIs usage. Especially when it comes to:
- User privacy
- Battery life
- User experience
In the case of the flashlight, the last two items are relevant. Apple will not let an app drain the battery when not in the foreground and iOS users are used to the fact that flashlight, camera, microphone... are immediately disabled when going to the background (with an exception for the microphone in some background modes cases).
To answer the comment on your initial post, iOS controls your hardware. So since Apple decided they don't want the light to stay on when the user closes the app, iOS will just power off the flash when your app goes in the background. Your app has no authority to prevent it.
When in background your application doesn't work or get any messages from the system.
The only cases when this is allowed are:
navigation application
audio player
Internet telephony
Unless you are designing any of the above you can not flash the user with anything.
If you only want to notify the user about something, you can create a notifier that will pop a message in the users window even if your application is in the background or entirely off. the user can click the message and then he will be back to your application
My app is an audio player, so it keeps running in the background. But flashlight works only when it's in the Foreground. No flashlight from the background.
try AVCaptureDevice
AVCaptureDevice

iPhone:don't want to exit game while ring/silent switch turns on from turns off mode

I am working on app in which audio file playing very vital role.
for playing audio file I am using AVaudioPlayer in my app.
but one problem is suppose device is in silent mode and user starts running the app
and suppose he/she turns on silent/ring switch in the middle of the app.
right now he/she must exit the game but I want such kind of functionality in
which He/she should not exit the app and in the middle of the app user should be
able to hear the sound when he turns on the ring/silent switch from the device.
iOS apps have the ability to play music in the background whether they be games or not, since multitasking was introduced in iOS.
See the following tutorial.
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_background-audio/
Whether its legit for a game to do this I seriously question. But thats your call.

How to invoke "Turn Off Airplane Mode" notification

In many applications, such as the Mail app, if the device is in airplane mode a notification will pop up that says "Turn Off Airplane Mode or Use Wi-Fi to Access Data."
I thought that this would automatically be invoked if my app tries to access the internet, but it is not. Is there a special method to do this, or if not how can I check if the device is in airplane mode and provide a link to Settings to disable it?
If you add the UIRequiresPersistentWifi key to your Info.plist and set it to YES, then if you're in Airplane mode, you'll get the standard "Turn Off Airplane Mode..." popup on launch.
I test in my app. I find it changed. "UIRequiresPersistentWifi" => "Application uses Wi-Fi".
I hope it will help somebody.
You could use the apple's reachablity framework when you app launches to check for network connectivity. Check this out
http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
I have a wrapper class for reachbiltiy APIs to make it simpler to use. (ASIHTTPRequest has one as well).
https://github.com/daltoniam/GPHTTPRequest
see the GPReachablity class for checking for connectivity. As far as a dialog prompt, not sure there is a way to push to the settings app. Any questions let me know.
If you want the standard Turn Off Airplane Mode or Use Wi-Fi to Access Data [settings | ok]
Add a new property in your info.plist by clicking the + sign at the top.
The new property is called UIRequiresPersistentWiFi (this is similar to postings above, but needs to be exact otherwise it doesn't register)
Change type from String to Boolean
Change value from NO to YES
Clean and rebuild your app
Take a look at this. Apparently, Airport control was moved by Apple into a separate framework
It seems there is no standard way to notify the user to turn airplane mode back on. As you mentioned, this obviously isn't very elegant, so I assume apple deleted this feature.

Determining if Airplane Mode is enabled on an iPhone?

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.
--
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.
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.
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.
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.
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.
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.
I don't know if it is possible to get this information, at least using public classes, but if what you need is to alert the user that he's in Airplane Mode, so with limited app functionality, you may set in your Info.plist file the UIRequiresPersistentWiFi property to "true". Then when Airplane mode is set you will get this message.
By the way note that this approach is better than just checking the Airplane Mode status, other than because it is system supported, as if the user enables Airplane mode and then re-enables Wi-Fi (still staying in Airplane Mode) then the system alert will not be displayed.
One solution might be to take a screenshot of the device and look at the colors present in that region. If they're orange, you're in airplane mode.
You really shouldn't be trying to check if Airplane Mode is enabled or not. What if Apple makes a change to how Airplane Mode works, where it will leave the GPS equipment enabled even when turned on? The best way to reliably detect whether GPS services are enabled is to implement the CLLocationManagerDelegate and let the APIs tell you whether GPS is available or not
Examining the NSError it may pass to you will let you know if there are problems to