tul*_*dev 6 react-native react-native-android react-native-firebase
我读
但这些不是react-native-firebase的解决方案。
我正在react-native-firebase用来处理通知。在前台,一切正常。我坚持使用后台状态。
我正在做一个聊天项目并制作一对一通话功能。当客户有电话时,我会向他们推送数据通知。在 iOS 中,我在客户端收到通知时使用了 CallKit,它运行良好。但是在 Android 中我有一个问题:我可以显示 ConnectionService UI 进行调用,但无法连接到我的 Web 套接字服务器,因为它在 Headless JS 服务上运行。所以我尝试自动打开应用程序。我想将呼叫屏幕显示为 Skype,并接受/拒绝呼叫。(Skype 可以在我有电话时启动该应用程序)
总结,成功步骤:
卡在这里:
TL;DR - 如何从 Headless JS 服务启动/运行/打开 Android 应用程序?
我深入研究 react-native-firebase,它捕获通知onMessageReceived并将通知消息发送到 Headless JS 服务。
// If the app is in the background we send it to the Headless JS Service
Intent headlessIntent = new Intent(
this.getApplicationContext(),
RNFirebaseBackgroundMessagingService.class
);
headlessIntent.putExtra("message", message);
this
.getApplicationContext()
.startService(headlessIntent);
HeadlessJsTaskService.acquireWakeLockNow(this.getApplicationContext());
任何帮助,将不胜感激
该库有助于从后台状态打开应用程序。 React Native 启动应用程序
如果您的应用程序从后台状态退出
你必须像这样在index.js中注册registerHeadlessTask
AppRegistry.registerHeadlessTask(
'ReactNativeFirebaseMessagingHeadlessTask',
() => notificationActionHandler,
);
Run Code Online (Sandbox Code Playgroud)
并在 notificationActionHandler 函数中调用库函数来打开应用程序
如果您的应用程序在后台运行,您可以订阅此内容
messaging().setBackgroundMessageHandler(remoteMessage => {
console.log('setBackgroundMessageHandler', remoteMessage.data);
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1248 次 |
| 最近记录: |