0

My app stops speaking when enter background and continues speech when entering foreground. I need to stop Speaking when app enters again foreground.

  • this link could help you https://stackoverflow.com/questions/28317036/text-to-speech-functionality-when-app-is-in-background-mode – Muzahid Jan 15 '18 at 12:33

1 Answers1

1

Implement this delegate method if code is global

- (void)applicationWillEnterForeground:(UIApplication *)application 
{
  /// stop speech

}

or listen to it in your viewController if it's not

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; 

//

 -(void)applicationWillEnterForeground:(NSNotification *)paramNotification
{



}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • I appreciate your help. But not working. i used like- (void)applicationWillEnterForeground:(UIApplication *)application { [speechSynthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate]; } – Yadukrishnan A Jan 15 '18 at 12:44
  • Not music. Text to Speech and i Use AVSpeechSynthesizer & AVSpeechUtterance. It stops speech when the app enter background but continues speech when entering foreground. I need to stop the speech when entering foreground. – Yadukrishnan A Jan 15 '18 at 12:48
  • try this - (void)applicationDidBecomeActive:(UIApplication *)application – Shehata Gamal Jan 15 '18 at 12:50
  • I dont need to play audio (Speech) in background. When the app enter background it stops the speech as desired. But when coming to foreground it resumes the Speech. And i need to stop the speech when entering foreground. – Yadukrishnan A Jan 15 '18 at 12:54
  • I got it: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; // Really thank you for your help. – Yadukrishnan A Jan 15 '18 at 13:22
  • you can use it or execute code in appdelegate if it's global – Shehata Gamal Jan 15 '18 at 13:29