当应用程序在后台运行时,Firebase通知[IOS]无法正常工作

时间:2019-02-26 07:56:52

标签: ios firebase cordova cordova-plugin-fcm

使用:

xcode控制台显示:

  • 应用进入后台
  • 设置状态背景
  • 与FCM断开连接

我有什么:

我在iphone上获得了令牌标识符,所以我想它可以工作,但是我不确定,因为当您打开应用程序时收到通知时,它确实会显示通知(如果有人知道如何解决,我会感激不尽),但我的问题是当应用程序进入后台时如何停止断开FCM插件的连接。

只有我拥有的代码

function onDeviceReady() {
        // Handle the Cordova pause and resume events
        document.addEventListener( 'pause', onPause.bind( this ), false );
        document.addEventListener('resume', onResume.bind(this), false);

        function checkConnection() {
            var networkState = navigator.connection.type;

            var states = {};
            states[Connection.UNKNOWN] = 'Ligação desconhecida';
            states[Connection.ETHERNET] = 'Ethernet connection';
            states[Connection.WIFI] = 'WiFi connection';
            states[Connection.CELL_2G] = 'Cell 2G connection';
            states[Connection.CELL_3G] = 'Cell 3G connection';
            states[Connection.CELL_4G] = 'Cell 4G connection';
            states[Connection.CELL] = 'Cell generic connection';
            states[Connection.NONE] = 'Sem ligação a internet';

            if (states[networkState] === states[Connection.NONE]) {
                alert("A aplicação necessida de internet para funcionar correctamente");
            }
        }

        FCMPlugin.getToken(function (token) {
            myToken = token;
            alert(token);
        }, function (error) {
            console.error(error);
        });

    }

1 个答案:

答案 0 :(得分:0)

您可能需要为此提供后台服务

  

https://github.com/anrip/cordova-plugin-background-service

document.addEventListener("pause", function(){
   window.BackgroundService.start(
       function(fn) { 
            //subscribe to your topic here
            FCMPlugin.subscribeToTopic('topicExample');
       },
       function() { console.log('err') }
   );
});