使用Firebase自定义点击Ionic通知 [英] Custom click on Ionic notification using Firebase

查看:549
本文介绍了使用Firebase自定义点击Ionic通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用离子和FCM(Firebase Cloud Messaging)进行通知。

我的应用程序收到通知,现在我有两个问题。首先,如果它是一个正常的通知,如 Firebase Console> Notification 中的高级选项,则不会播放任何声音,但是当它是数据通知时,则会播放声音。其次,我想打开我的应用程序的特定页面上的通知点击。



那么我该怎么做?

注意:我正在使用ionic而不是ionic2。 $ b我们在两种情况下都有声音。你有没有尝试发送一个空的数据对象?



第二个问题:
假设你使用Cordova FCM插件。否则,请使用

 > cordova插件添加cordova-plugin-fcm --save 

使用带有ID的数据到正确的数据页,然后执行下列操作:

<$ p $ (函数()函数){$ b $ angular.module('app',['ionic'])
.run(function($ ionicPlatform){
$ ionicPlatform.ready $ b if(window.cordova){
FCMPlugin.onNotification(
function(data){
if(data.wasTapped){
//设备托盘上收到通知,
$ state.go('yourpage',{id:data.pageId});
console.log('onNotification tapped true');
} else {
//通知在前台收到,用户需要通知
console.log('onNotification tapped false');
}
),
函数(msg){
console.log('onNotification callback successfully registered:'+ msg);
},
函数(err){
console.log('注册onNotification回调错误:'+ err);
}
);
}
});
});


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.

解决方案

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);
                }
            );
        }
    });
});

这篇关于使用Firebase自定义点击Ionic通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆