如何在react native(iOS)中处理FCM仅数据消息

问题描述 投票:0回答:1

在Android上,我可以像这些代码那样获取和处理“仅数据消息”。

bgMessaging.js

// @flow
import firebase from 'react-native-firebase';
// Optional flow type
import type { RemoteMessage } from 'react-native-firebase';

export default async (message: RemoteMessage) => {
    // handle your message

    return Promise.resolve();
}

index.js

import bgMessaging from './src/bgMessaging'; // <-- Import the file you created in (2)

// Current main application
AppRegistry.registerComponent('ReactNativeFirebaseDemo', () => bootstrap);
// New task registration
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging); // <-- Add this line

但是,在iOS上,当应用程序被杀死(不在进程中时,如何处理“仅数据消息”?

-

我想以某种逻辑显示通知。

如果服务器发送以下数据。

{
    "to": "asdf",
    "content_available": true,
    "priority": "high",
    "mutable_content": true,
    "data": {
        title: "{name} hellow!"
    }
}

应用程序应从数据库(如领域)获取用户名。并显示类似“ Tom hellow”

的通知

如何在react-native(ios)中做到这一点?

firebase react-native firebase-cloud-messaging react-native-firebase
1个回答
1
投票

请将data替换为aps,或者您可以使用另一个参数aps或可以在aps中获取数据字典

     "to": "asdf",
    "content_available": true,
    "priority": "high",
    "mutable_content": true,
    "data": {
        title: "{name} hellow!"
    },
  "aps": {
        title: "{name} hellow!"
    }
© www.soinside.com 2019 - 2024. All rights reserved.