react-native-tts icon indicating copy to clipboard operation
react-native-tts copied to clipboard

Cannot play audio after OneSignal notification is received

Open anta40 opened this issue 5 months ago • 0 comments

I want to play audio notification after OneSignal notification is received. Here's my code (on App.tsx):

    const handleForegroundNotification = (event: any) => {
      console.log('Foreground Notification:', event);
      event.notification.display(); 
      setTimeout(() => {
        if (AppState.currentState === 'active') {
          Tts.getInitStatus().then(() => {
            if (lng == 'id'){
              Tts.setDefaultLanguage('id');
              Tts.speak("Pembayaran diterima. " + Terbilang(12500) + " rupiah");
            }
            else {
              Tts.setDefaultLanguage('en-US');
              Tts.speak("Payment accepted. " + numberToWords(12500) + " rupiah");
            }
          }).catch(err => {
            console.error('TTS init error', err);
          });
        } else {
          console.log('App not in foreground, skipping TTS');
        }
      }, 1000); 
    };

On Android 15 simulator, after OneSignal notification is received, audio is played (perhaps after adding android.permission.FOREGROUND_SERVICE and android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK permissions). But on iOS 18.3 simulator, no audio is played at all after OneSignal notification is arrived. Found this on the log: TTS init error [Error: Function not implemented]

I'm using RN 0.71.0 and RN TTS 4.1.1

anta40 avatar Jul 22 '25 17:07 anta40