简体   繁体   English

如何从 Flutter 应用程序发送推送通知

[英]how to Send push notifications from Flutter app

I use firebase messaging to push notifications.我使用 firebase 消息来推送通知。

Now i push notifications from console to users on app, but I want the user to push notifications from app to another user when send message.现在我将通知从控制台推送到应用程序上的用户,但我希望用户在发送消息时将通知从应用程序推送到另一个用户。 How can I do that?我怎样才能做到这一点?

Knowing that I have saved the device ID of each user on Firestore and the ID is renewed every time the user logs into the application.知道我已经在 Firestore 上保存了每个用户的设备 ID,并且每次用户登录应用程序时都会更新 ID。

I tried using the following code to send notifications in case the user sends a message, but it didn't work我尝试使用以下代码发送通知,以防用户发送消息,但它不起作用

sendNotification(String body, String idToken) async {
    await http.post(
      (Uri.parse('https://fcm.googleapis.com/fcm/send')),
      headers: <String, String>{
        'Content-Type': 'application/json',
        'Authorization': 'key=$servitoken',
      },
      body: jsonEncode(
        <String, dynamic>{
          'notification': <String, dynamic>{
            'body': "${body.toString()}",
            'title': "!"
          },
          'priority': 'high',
          'data': <String, dynamic>{
            'click_action': 'FLUTTER_NOTIFICATION_CLICK',
            'id': '1',
            'status': 'done'
          },
          'to': await "${idToken}",
        },
      ),
    );
  }

,## ,##

I will recommend you to use onesignal instead of just using firebase cloud messaging.我会建议您使用 onesignal 而不是仅使用 firebase 云消息传递。 Onesignal is easy to use and can make your development life more Onesignal 易于使用,可以让您的开发生活更丰富

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使推送通知针对 flutter 应用程序? - How to make push notifications target a flutter app? 从用户应用程序向管理应用程序发送推送通知 - Flutter - Send Push notification from user app to admin app - Flutter 如何通过 FCM 将推送通知从 arduino 发送到 android? - How to send push notifications from arduino to android via FCM? 如何在不使用 Firebase 控制台的情况下使用 FCM 在 Flutter 应用程序中触发推送通知? - How to trigger push notifications in Flutter app using FCM without using the Firebase Console? 从 nodejs 使用 firebase-admin 发送推送通知 - Send push notifications with firebase-admin from nodejs 从一个 Pinpoint 项目向多个 iOS 应用程序发送推送通知 - Send push notifications from one Pinpoint project to multiple iOS apps 如何通过 AWS Pinpoint 和 firebase 发送 iOS 推送通知? - How to send iOS push notifications through AWS Pinpoint and firebase? Flutter 使用 FCM 的推送通知在 iOS 上不起作用 - Flutter push notifications using FCM not working on iOS 如何通过 AWS 为 Todo App 发送电子邮件/短信通知? - How to send email/SMS notifications via AWS for Todo App? 如何翻译 Firebase 推送通知? - How to translate Firebase Push Notifications?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM