0

I have iOS7 application that play some voice commands using Apple TTS engine, I am using this to setup my audio session:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
                          withOptions:AVAudioSessionCategoryOptionDuckOthers
                                error:&error];
[[AVAudioSession sharedInstance] setActive:YES error:&err];

then play my command.

The problem that I have now is that if my phone receives a phone call my application will continue playing its voice command during the phone call, the expectation is that my application will be paused once I answered the phone call and then resume after the call is done.

Is there any thing that I can do to make sure that the phone call will pause my app?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52

1 Answers1

0

When a phone call comes in, the - (void)applicationWillResignActive:(UIApplication *)application method should be called in you app delegate. This is where you should pause the audio.

67cherries
  • 6,931
  • 7
  • 35
  • 51
  • Thank you for your help, but what if my application is already in the background when I received the call? the - `(void)applicationWillResignActive:(UIApplication *)application` method will NOT be called in this case !! (I tried it it did not get called) – user3456603 May 22 '14 at 21:03
  • Do you need to play sound when your app is in the background? If you don't you can just pause the audio when the `-applicationDidEnterBackground:` method is called. – 67cherries May 22 '14 at 21:25
  • Thank you, I have this scenario, my app in the foreground, a phone call comes, my app is receiving `UIApplicationWillResignActiveNotification` and the app become in `UIApplicationStateInactive` state, I dropped the call (i.e. clicked the red button) my app is stays in the `UIApplicationStateInactive` state, I was expecting it will become active. – user3456603 May 27 '14 at 19:07