Appcelerator-Titanium - Не получает push-сообщения данных fcm, когда приложение находится в фоновом режиме / закрыто - PullRequest
1 голос
/ 22 апреля 2019

Я перенесу существующую функциональность GCM в FCM в приложении Appcelerator-Titanium, которое использует каркас сплава. Я использую следующий сторонний модуль для FCM -

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

Приложение ранее использовало следующий модуль для GCM -

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

Приложение не получает push-сообщения с данными в фоновом режиме / закрыто, но нормально работает на переднем плане.

Ниже приведен пример кода в моем 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 содержит код для отображения push-уведомлений в области уведомлений.

...