Custom click on Ionic notification using Firebase

匿名 (未验证) 提交于 2019-12-03 00:57:01

问题:

I have been using ionic and FCM (Firebase Cloud Messaging) for notification.

I get the notification on my app and now I have 2 issues. First, if its a normal notification like not with advanced options in Firebase Console > Notification, then it doesn't play any sound, but when it's data Notification, then it does play a sound. Second, I want to open a particular page of my app on notification click.

So how do I do that?

Note: I am using ionic not an ionic2.

回答1:

First issue: We have sound in both situations. Have you tried to send an empty data object?

Second issue: Just assuming you use the Cordova FCM plugin. Otherwise install it with

cordova plugin add cordova-plugin-fcm --save 

Use the data with an ID to the right datapage and then do something like:

angular.module('app', ['ionic']) .run(function ($ionicPlatform) {     $ionicPlatform.ready(function() {         if(window.cordova) {             FCMPlugin.onNotification(                 function(data){                     if(data.wasTapped){                         //Notification was received on device tray and tapped by the user.                         $state.go('yourpage', {id:data.pageId});                         console.log('onNotification tapped true');                     } else {                         //Notification was received in foreground. User needs to be notified.                         console.log('onNotification tapped false');                     }                 },                 function(msg){                     console.log('onNotification callback successfully registered: ' + msg);                 },                 function(err){                     console.log('Error registering onNotification callback: ' + err);                 }             );         }     }); }); 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!