【问题标题】:How to send Push Notifications using php in flutter App?如何在 flutter App 中使用 php 发送推送通知?
【发布时间】:2023-02-02 17:41:22
【问题描述】:

这里我有两个应用程序。一个像管理员,另一个像客户。

当我在管理应用程序中上传图像时,该图像显示在客户应用程序中。这里我使用 PHP 作为后端在管理应用程序中发布图像并在客户应用程序中获取图像。我的问题是 - 我想在管理员上传图片时向客户发送通知。

注意:如果可能,我需要在不使用 Firebase 的情况下完成此任务。

提前致谢。

【问题讨论】:

    标签: php flutter dart


    【解决方案1】:

    我试着分步骤解释这个过程:

    假设您的 Flutter 应用程序已与 Firebase FCM 正确集成

    1. 管理员发布图片

    2. 服务器发送推送通知,你可以参考fcm http协议here或者下面你的fcm body的json结构

      {
       "to" : "<TOKEN>", //if you want the fcm to be sent to specific user
       "notification" : {
           "title": "Notification Title",
           "body" : "Notification Body"
       },
       "data":{
          "click_action": "FLUTTER_NOTIFICATION_CLICK",
          "key": "<ANY STRING YOU WOULD LIKE TO DIFFERENTIATE THE NOTIFICATION>" //eg: "image_update"
       }
      }
      
      
      1. 在 Flutter 代码中,配置 onMessage 以告知应用在收到带有键“image_update”的推送通知时需要执行的操作
          FirebaseMessaging.onMessage.listen((RemoteMessage message) {
            if(message.data['key'] == "image_update"){
               //call GET image API and display on app
            }
            //note: you can differentiate notification type with "key" so that you can perform different functions for each notification type
            return;
          });
      
      

    【讨论】:

    【解决方案2】:

    您可以通过 Api 表单 firebase 执行此操作。 您可以参考: This link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-19
      • 1970-01-01
      • 2017-08-12
      • 1970-01-01
      • 2015-11-23
      • 1970-01-01
      • 2015-01-06
      相关资源
      最近更新 更多