簡體   English   中英

如何在 flutter 應用程序中使用 php 發送推送通知?

[英]How to send Push Notifications using php in flutter App?

在這里,我有兩個應用程序。 一個充當管理員,另一個充當客戶。

當我在管理應用程序中上傳圖像時,該圖像顯示在客戶應用程序中。 這里使用 PHP 作為后端在管理應用程序中發布圖像並在客戶應用程序中獲取圖像。 我的問題是 - 我想在管理員上傳圖片時向客戶發送通知。

注意:如果可能,我需要在不使用 Firebase 的情況下執行此任務。

提前致謝。

我嘗試分步驟解釋該過程:

假設您的 Flutter 應用程序與Firebase FCM正確集成

  1. 管理員發布圖片

  2. 服務器發送推送通知,你可以參考這里的 fcm http 協議或者你下面的 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;
    });

在開始之前確保您的項目指向 Firebase 服務器。 這可以通過打開 pubspec.yaml 文件並添加以下代碼來完成。 要將庫添加到您的 flutter 應用程序,您需要按照下面提到的步驟進行操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM