Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 5分钟后收到Firebase在应用程序关闭时发出的纯数据消息_React Native_Firebase Cloud Messaging_React Native Firebase - Fatal编程技术网

React native 5分钟后收到Firebase在应用程序关闭时发出的纯数据消息

React native 5分钟后收到Firebase在应用程序关闭时发出的纯数据消息,react-native,firebase-cloud-messaging,react-native-firebase,React Native,Firebase Cloud Messaging,React Native Firebase,当应用程序被用户关闭时,即当用户在最近的应用程序列表中将应用程序拖到一边时,我试图在Android托盘上显示一条数据消息。尽管如此,数据消息的接收方式如下: 应用程序已关闭。已发送数据消息 应用程序关闭时未收到消息 应用程序已打开 4~5分钟后,数据信息被接收并显示在Android托盘中 为了实现这一点,我使用了react native firebaselib,遵循它的特性 上面的代码在后台运行良好,我的意思是当应用程序只是“最小化”到次要计划时 AndroidManifest.xml、Head

当应用程序被用户关闭时,即当用户在最近的应用程序列表中将应用程序拖到一边时,我试图在Android托盘上显示一条数据消息。尽管如此,数据消息的接收方式如下:

  • 应用程序已关闭。已发送数据消息
  • 应用程序关闭时未收到消息
  • 应用程序已打开
  • 4~5分钟后,数据信息被接收并显示在Android托盘中
  • 为了实现这一点,我使用了react native firebaselib,遵循它的特性

    上面的代码在后台运行良好,我的意思是当应用程序只是“最小化”到次要计划时

    AndroidManifest.xml、HeadlessTask和mainaplication.java理论上与docs一致。我只是在Android托盘中显示空白UI进行测试

    邮递员正在发送的邮件:

    {
    "to": "erVxmCT6rgA:APA91bGn6q9...",
    
    "data": {
        "custom1": "custom1",
        "custom2": "custom2"
       }
    }
    

    问题:一旦在后台运行,会出现什么问题?为什么会发生这种行为?

    经过深入搜索,我可以找到答案

    我在华硕设备上运行应用程序。根据这一点,华硕智能手机有一个性能技巧,可以延长电池寿命,因此当你从最近的应用列表中刷走一个应用时,你就是在强迫应用停止。因此,负责接收消息的HeadlessJSTask取自android进程列表

    我还对我的代码进行了一些编辑:

    固定承诺:

    export default async (message: RemoteMessage) => {
    
        const notification = new firebase.notifications.Notification();
                  notification.android.setPriority(firebase.notifications.Android.Priority.High);
                  notification.android.setChannelId("test-channel");
                  notification.setTitle(message.data.custom1);
    
            firebase.notifications().displayNotification(notification);
    
        return Promise.resolve(message);
    }
    
    在我们的数据消息中设置高优先级(对于后台和应用程序关闭消息是必需的):

    export default async (message: RemoteMessage) => {
    
        const notification = new firebase.notifications.Notification();
                  notification.android.setPriority(firebase.notifications.Android.Priority.High);
                  notification.android.setChannelId("test-channel");
                  notification.setTitle(message.data.custom1);
    
            firebase.notifications().displayNotification(notification);
    
        return Promise.resolve(message);
    }
    
    {
    
    "to": "cKUNOaOnvaY:APA91bFVAPLSuHogmZfxc1GlhqOhEkxcscoRvZxRrzno0XjyDkqYZVmNqJVL4v6mcQgH4p9zt9Zxz5aDugCjNy7CBg_pbXb8u8X6336K0x6WffdXoGOl50lCtHt46oS78Yyc9XM3gPJQ",
    
    "data": {
        "custom1": "custom1",
        "custom2": "custom2"
    },
    
    "priority": "high"
    
    }