views:

149

answers:

3

Is it possible to identify whether the user is on a phone call while using an app.

Here is the scenario:

  1. I get a call
  2. I accept the call
  3. Tap the home button
  4. Launch an app

At this point can I tell this app that a call is going on in background?

Getting to know the screen is not a full blown option. Because it makes life difficult when on internet tethering.

+1  A: 

You could check the height of the status bar. If it's more than 20px, you're either on a call, or tethering (which is not supported on AT&T, so it must be on a call if you're in the US).

[UIApplication sharedApplication].statusBarFrame
Ben Gottlieb
Wally Lawless
Ben Gottlieb
Whenever I use [UIApplication sharedApplication].statusBarFrame in a NSLog statement, it shows the frame to be "0". What's up?
Jonah
Are you wrapping the frame in NSStringFromCGRect(...)?
Ben Gottlieb
+1  A: 

There isn't a public API for any phone state or functionality, so you'll have to rely on side-effects of being on a call.

You can either check the status bar like Ben Gottlieb suggested, or you can try to initialize an audio recording, if it fails with an error of already in use, you can be fairly certain the microphone is being used for a call.

Ben S
Or for a voice memo.
Noah Witherspoon
+1  A: 

To elaborate on what Ben said, you'll want to subtract [UIApplication sharedApplication].statusBarFrame from the height you set your View to.

pixel