应用程序被杀死时如何使用Cordova发送推送通知

时间:2018-09-08 11:28:24

标签: android cordova push-notification firebase-cloud-messaging

const FCM = cordova.exec('fcm-node');

const apiKey = 'AIzaSyDrzCXUxUmlBiGQNKFkZavsLKv1zjDKc1Y';`enter code here`

const deviceID = 
'fBgVGG3AB0:APA91bEJdEjnRmMWi8lLksi9gPv6ztUpokdYWzyjx7
oWCLb7lktoshK34ozbL7kxcTUizwXZZeW01wvjgcPC34377IZ6czXuCP3N77
vzwmXKOYP2orcIdo572sjPfGItXah1HjwJdF-B';

const fcm = new FCM(apiKey);

const message = {
    to: deviceID,
    data: {
        title: 'Force Start',
        message: 'This notification should restart the app',
        'force-start': '1'
    }
};

fcm.send(message, (err, response) => {
    if (err) {
        alert(err);
        alert('Something has gone wrong!');
    } else {
        alert('Successfully sent with response: ', response);
    }
});

0 个答案:

没有答案