2

I have camera view using AVFoundation and if phone call or Skype call is active then we can't use camera.

How can i check if AVFoundation will not open then i need to open other view without using camera.

if i will check this-

BOOL isPlayingWithOthers = [[AVAudioSession sharedInstance] isOtherAudioPlaying];

then it will not open when any other app playing audio.

Any suggestions ?

San007
  • 762
  • 1
  • 9
  • 30

3 Answers3

2

The CTCallCenter object has a currentCalls property which is an NSSet of the current calls. If there is a call then the currentCalls property should be != nil.

If you want to know if any of the calls is actually connected, then you'll have to iterate through the current calls and check the callState to determine if it is CTCallStateConnected or not.

#import <CoreTelephony/CTCallCenter.h>
#import <CoreTelephony/CTCall.h>

-(bool)isOnPhoneCall {
    /*
     Returns YES if the user is currently on a phone call
     */

    CTCallCenter *callCenter = [[[CTCallCenter alloc] init] autorelease];
    for (CTCall *call in callCenter.currentCalls)  {
        if (call.callState == CTCallStateConnected) {
            return YES;
        }
    }
    return NO;
}
Tarun
  • 102
  • 7
2

I am using this method in Swift, Tarun answer helped me.

import CallKit

func isOnPhoneCall() -> Bool {
    /*
     Returns true if the user is currently on a phone call
     */
    for call in CXCallObserver().calls {
        if call.hasEnded == false {
            return true
        }
    }
    return false
}
Savas Adar
  • 4,083
  • 3
  • 46
  • 54
-2

Your app delegate will receive the -applicationDidResignActive message and your app can listen for the UIApplicationDidResignActiveNotification. These will be received when your app is interrupted by a call as well as in other cases where the app is interrupted, such as when the screen locks or the user presses the lock button.

For more details how to handle interruptions in Responding to Interruptions.

Also refer stack overflow post on How can we detect call interruption in our iphone application?

Community
  • 1
  • 1
Dipen Panchasara
  • 13,480
  • 5
  • 47
  • 57
  • This will work when app is active and then got interrupted, Any other way to check on app start ? – San007 Nov 27 '15 at 05:56
  • There is no certain way to achieve it during app launch, but there is a work around by checking status bar frame, its not 100% solution. refer existing stack post [Detecting if user has in call status bar](http://stackoverflow.com/questions/23841418/detecting-if-user-has-in-call-status-bar) – Dipen Panchasara Nov 27 '15 at 06:07