Skip to content

Cannot play audio after OneSignal notification is received #287

@anta40

Description

@anta40

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions