Appcelerator-Titanium-当应用程序处于后台/关闭状态时,未收到fcm数据推送消息

时间:2019-04-22 12:00:13

标签: android firebase-cloud-messaging titanium

我正在使用合金框架的Appcelerator-Titanium应用程序中将现有GCM功能迁移到FCM。 我正在将以下第三方模块用于FCM-

https://github.com/hansemannn/titanium-firebase-cloud-messaging/

应用先前已将以下模块用于GCM-

https://github.com/saurabh-vijay004/gcm.js-master

在后台/关闭时,应用程序未接收到推送数据消息,但在前台工作正常。

以下是我的index.js中的示例代码-

var core = require('firebase.core');
    core.configure({
        file : "google-services.json"
    });
    var fcm = require('firebase.cloudmessaging');
    var androidNotification = require('/androidNotification');

    registerAndroid();
    function registerAndroid() {
        // Called when the Firebase token is registered or refreshed.
        fcm.addEventListener('didRefreshRegistrationToken', function(e) {
            Ti.API.info('Token', e.fcmToken);
            Ti.App.Properties.setString('push_token', e.fcmToken);
        });
        // Called when direct messages arrive. Note that these are different from push notifications.
        fcm.addEventListener('didReceiveMessage', function(e) {
            Ti.API.info('Message', JSON.stringify(e.message.data.message));
            androidNotification.sendNotification(e.message.data.message);
        });

        if (OS_ANDROID) {

            var channel = Ti.Android.NotificationManager.createNotificationChannel({
                id : 'nube_channel',
                name : 'NUBE CHANNEL',
                importance : Ti.Android.IMPORTANCE_DEFAULT,
                enableLights : true,
                enableVibration : true,
                showBadge : true
            });
            fcm.notificationChannel = channel;
        }

        // Register the device with the FCM service.
        fcm.registerForPushNotifications();
        // Check if token is already available.
        if (fcm.fcmToken) {
            Ti.API.info('FCM-Token', fcm.fcmToken);
            Ti.App.Properties.setString('push_token', fcm.fcmToken);
        } else {
            Ti.API.info('Token is empty. Waiting for the token callback ...');
        }
    }

androidNotification.js文件具有在通知托盘中显示推送通知的代码。

0 个答案:

没有答案