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



在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(中做到这一点?

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

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

最新更新