Ionic Push custom sound not works!

Ionic 2 Push custom sound not works!

Please help how to do?

What did you do? What code did you write?

1 Like

I am using FCM as backend and trying to recieve push using cordova FCM plugin. Push receved but no custom cound.

Use push plugin too. Same for it.

Please show some code for implementation.

1 Like
   const options: PushOptions = {
          android: {
              senderID: 'Here is my send id',
              sound: true,
              vibrate: true,
              clearBadge: true,
              icon: 'icon',
              clearNotifications: true,
          },
          ios: {
              alert: true,
              badge: true,
              sound: true,
              clearBadge: true
          },
          windows: {}
      };

      const pushObject: PushObject = this.push.init(options);

      pushObject.on('notification').subscribe((notification: any) => {
          console.log('message', notification.message);
          let self = this;
          if (notification.additionalData.foreground) {
              // if application open, show popup
              let confirmAlert = this.alertCtrl.create({
                  title: 'Notification...',
                  message: JSON.stringify(notification),
                  buttons: [{
                      text: 'Ignore',
                      role: 'cancel'
                  }, {
                          text: 'View',
                          handler: () => {
                              //TODO: Your logic here
                              //self.nav.push(DetailsPage, {message: data.message});
                          }
                      }]
              });
              confirmAlert.present();
          } else {
              //if user NOT using app and push notification comes
              //TODO: Your logic on click of push notification directly
            //  this.nav.push(Contact, { message: notification.message });
          }
      });

      pushObject.on('registration').subscribe((registration: any) =>
      {
          console.log("Registration Id : " + registration);
      });

      pushObject.on('error').subscribe((error: any) => {
          console.log("Error : " + error);
      });

I am sending push messages from Firebase Cloud Messaging notifications.

I am receiving messages but I don’t know how to play custom sound there.

I have placed mp3 Preformatted textsound file in res>>raw folder but nothing works.

I would recommend you check on this, I hope it helps.

https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#sound

I already read that documents. I have fixed the issue. I was using old version of push plugin.

2 Likes

Anyways, Thank you so much.

Hi, did u somehow tried on ios device yet? i’m facing problems on playing custom sound on ios, hope someone could help

I have this problem on Android 8.0.0. Ionic 3, also sending notifications via FCM. Is there any solution?