שלח הודעות למספר מכשירים

כדי למקד הודעה למספר מכשירים, השתמש בהודעות נושא . תכונה זו מאפשרת לך לשלוח הודעה למספר מכשירים שהצטרפו לנושא מסוים.

מדריך זה מתמקד בשליחת הודעות נושא משרת האפליקציות שלך באמצעות ה- Admin SDK או REST API עבור FCM, וקבלה וטיפול בהן באפליקציית אנדרואיד. אנו נסקור את הטיפול בהודעות הן עבור אפליקציות ברקע והן עבור אפליקציות בחזית. כל השלבים להשיג זאת מכוסים, מההגדרה ועד לאימות.

הגדר את ה-SDK

חלק זה עשוי לכסות את השלבים שכבר השלמת אם הגדרת אפליקציית לקוח אנדרואיד עבור FCM או עברת את השלבים לשליחת ההודעה הראשונה שלך .

לפני שאתה מתחיל

  • התקן או עדכן את Android Studio לגרסה האחרונה שלו.

  • ודא שהפרויקט שלך עומד בדרישות הבאות:

    • ממקד לרמת API 19 (KitKat) ומעלה
    • משתמש ב-Android 4.4 ומעלה
    • משתמש ב-Jetpack (AndroidX) , הכולל עמידה בדרישות הגרסה הבאות:
      • com.android.tools.build:gradle v7.3.0 ואילך
      • compileSdkVersion 28 ואילך
  • הגדר מכשיר פיזי או השתמש באמולטור כדי להפעיל את האפליקציה שלך.
    שים לב ש- SDK של Firebase עם תלות בשירותי Google Play דורשים שהמכשיר או האמולטור יותקנו בשירותי Google Play.

  • היכנס ל-Firebase באמצעות חשבון Google שלך.

אם עדיין אין לך פרויקט אנדרואיד ורק רוצה לנסות מוצר של Firebase, תוכל להוריד את אחת מדוגמאות ההתחלה המהירה שלנו.

צור פרויקט Firebase

לפני שתוכל להוסיף את Firebase לאפליקציית Android שלך, עליך ליצור פרויקט Firebase כדי להתחבר לאפליקציית Android שלך. בקר בהבנת פרויקטים של Firebase כדי ללמוד עוד על פרויקטים של Firebase.

רשום את האפליקציה שלך ב-Firebase

כדי להשתמש ב-Firebase באפליקציית Android שלך, עליך לרשום את האפליקציה שלך בפרויקט Firebase שלך. רישום האפליקציה שלך נקרא לעתים קרובות "הוספת" האפליקציה שלך לפרויקט שלך.

  1. עבור אל מסוף Firebase .

  2. במרכז דף סקירת הפרויקט, לחץ על סמל אנדרואיד ( ) או הוסף אפליקציה כדי להפעיל את זרימת העבודה של ההגדרה.

  3. הזן את שם החבילה של האפליקציה שלך בשדה שם החבילה של Android .

  4. (אופציונלי) הזן מידע אחר על האפליקציה: כינוי לאפליקציה ואישור חתימת באגים SHA-1 .

  5. לחץ על הרשמה אפליקציה .

הוסף קובץ תצורה של Firebase

  1. הורד ולאחר מכן הוסף את קובץ התצורה של Firebase Android ( google-services.json ) לאפליקציה שלך:

    1. לחץ על הורד את google-services.json כדי להשיג את קובץ התצורה של Firebase Android שלך.

    2. העבר את קובץ התצורה שלך לספריית השורש של המודול (ברמת האפליקציה) של האפליקציה שלך.

  2. כדי להפוך את הערכים בקובץ התצורה google-services.json שלך לנגישים ל-SDK של Firebase, אתה צריך את הפלאגין של שירותי Google Gradle ( google-services ).

    1. בקובץ Gradle ברמת השורש (ברמת הפרויקט) ( <project>/build.gradle.kts או <project>/build.gradle ), הוסף את הפלאגין של שירותי Google כתלות:

      Kotlin

      plugins {
        id("com.android.application") version "7.3.0" apply false
        // ...
      
        // Add the dependency for the Google services Gradle plugin
        id("com.google.gms.google-services") version "4.4.1" apply false
      }
      

      Groovy

      plugins {
        id 'com.android.application' version '7.3.0' apply false
        // ...
      
        // Add the dependency for the Google services Gradle plugin
        id 'com.google.gms.google-services' version '4.4.1' apply false
      }
      
    2. בקובץ Gradle של המודול (ברמת האפליקציה) (בדרך כלל <project>/<app-module>/build.gradle.kts או <project>/<app-module>/build.gradle ), הוסף את הפלאגין של שירותי Google:

      Kotlin

      plugins {
        id("com.android.application")
      
        // Add the Google services Gradle plugin
        id("com.google.gms.google-services")
        // ...
      }
      

      Groovy

      plugins {
        id 'com.android.application'
      
        // Add the Google services Gradle plugin
        id 'com.google.gms.google-services'
        // ...
      }
      

הוסף ערכות SDK של Firebase לאפליקציה שלך

  1. בקובץ Gradle של המודול (ברמת האפליקציה) (בדרך כלל <project>/<app-module>/build.gradle.kts או <project>/<app-module>/build.gradle ), הוסף את התלות עבור Firebase Cloud ספריית הודעות עבור אנדרואיד. אנו ממליצים להשתמש ב- Firebase Android BoM כדי לשלוט בגירסאות של הספרייה.

    לחוויה אופטימלית עם Firebase Cloud Messaging, אנו ממליצים להפעיל את Google Analytics בפרויקט Firebase שלך ​​ולהוסיף את Firebase SDK עבור Google Analytics לאפליקציה שלך.

    dependencies {
        // Import the BoM for the Firebase platform
        implementation(platform("com.google.firebase:firebase-bom:32.8.0"))
    
        // Add the dependencies for the Firebase Cloud Messaging and Analytics libraries
        // When using the BoM, you don't specify versions in Firebase library dependencies
        implementation("com.google.firebase:firebase-messaging")
        implementation("com.google.firebase:firebase-analytics")
    }
    

    באמצעות Firebase Android BoM , האפליקציה שלך תמיד תשתמש בגרסאות תואמות של ספריות Firebase Android.

    (אלטרנטיבי) הוסף תלות בספריית Firebase מבלי להשתמש ב-BoM

    אם תבחר שלא להשתמש ב-Firebase BoM, עליך לציין כל גרסת ספריית Firebase בשורת התלות שלה.

    שים לב שאם אתה משתמש במספר ספריות Firebase באפליקציה שלך, אנו ממליצים בחום להשתמש ב-BoM לניהול גרסאות ספרייה, מה שמבטיח שכל הגרסאות תואמות.

    dependencies {
        // Add the dependencies for the Firebase Cloud Messaging and Analytics libraries
        // When NOT using the BoM, you must specify versions in Firebase library dependencies
        implementation("com.google.firebase:firebase-messaging:23.4.1")
        implementation("com.google.firebase:firebase-analytics:21.6.1")
    }
    
    מחפש מודול ספרייה ספציפי לקוטלין? החל מאוקטובר 2023 (Firebase BoM 32.5.0) , מפתחי Kotlin ו-Java יכולים להיות תלויים במודול הספרייה הראשי (לפרטים, עיין בשאלות הנפוצות לגבי יוזמה זו ).

  2. סנכרן את פרויקט האנדרואיד שלך עם קבצי Gradle.

הירשם לאפליקציית הלקוח לנושא

אפליקציות לקוח יכולות להירשם לכל נושא קיים, או שהן יכולות ליצור נושא חדש. כאשר אפליקציית לקוח נרשמת לשם נושא חדש (כזה שלא קיים כבר עבור פרויקט Firebase שלך), נושא חדש בשם זה נוצר ב-FCM וכל לקוח יכול להירשם אליו לאחר מכן.

כדי להירשם לנושא, אפליקציית הלקוח קוראת ל-Firebase Cloud Messaging subscribeToTopic() עם שם הנושא של FCM. שיטה זו מחזירה Task , שבה יכול לשמש מאזין השלמה כדי לקבוע אם המנוי הצליח:

Kotlin+KTX

Firebase.messaging.subscribeToTopic("weather")
    .addOnCompleteListener { task ->
        var msg = "Subscribed"
        if (!task.isSuccessful) {
            msg = "Subscribe failed"
        }
        Log.d(TAG, msg)
        Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
    }

Java

FirebaseMessaging.getInstance().subscribeToTopic("weather")
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                String msg = "Subscribed";
                if (!task.isSuccessful()) {
                    msg = "Subscribe failed";
                }
                Log.d(TAG, msg);
                Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
            }
        });

כדי לבטל את המנוי, אפליקציית הלקוח קוראת ל-Firebase Cloud Messaging unsubscribeFromTopic() עם שם הנושא.

קבלה וטיפול בהודעות בנושא

FCM מעביר הודעות נושא באותו אופן כמו הודעות אחרות במורד הזרם.

כדי לקבל הודעות, השתמש בשירות שמרחיב את FirebaseMessagingService . השירות שלך צריך לעקוף את ההתקשרות חוזרת של onMessageReceived ו- onDeletedMessages .

חלון הזמן לטיפול בהודעה עשוי להיות קצר מ-20 שניות, בהתאם לעיכובים שנגרמו לפני הקריאה onMessageReceived , כולל עיכובים של מערכת ההפעלה, זמן הפעלת האפליקציה, שהשרשור הראשי נחסם על ידי פעולות אחרות, או שיחות onMessageReceived קודמות שנמשכות זמן רב מדי. לאחר זמן זה, התנהגויות שונות של מערכת ההפעלה, כגון הרג תהליך של אנדרואיד או מגבלות ביצוע ברקע של Android O עלולות להפריע ליכולת שלך להשלים את עבודתך.

onMessageReceived מסופק עבור רוב סוגי ההודעות, למעט החריגים הבאים:

  • הודעות התראה נשלחות כאשר האפליקציה שלך ברקע . במקרה זה, ההודעה מועברת למגש המערכת של המכשיר. הקשה של משתמש על הודעה פותחת את משגר האפליקציות כברירת מחדל.

  • הודעות עם התראה וגם מטען נתונים, כשהן מתקבלות ברקע . במקרה זה, ההודעה נמסרת למגש המערכת של המכשיר, ומטען הנתונים נמסר בתוספות של כוונת פעילות המשגר ​​שלך.

לסיכום:

מצב האפליקציה הוֹדָעָה נתונים שניהם
חֲזִית onMessageReceived onMessageReceived onMessageReceived
רקע כללי מגש מערכת onMessageReceived הודעה: מגש מערכת
נתונים: בתוספות של הכוונה.
למידע נוסף על סוגי הודעות, ראה התראות והודעות נתונים .

ערוך את מניפסט האפליקציה

כדי להשתמש FirebaseMessagingService , עליך להוסיף את הדברים הבאים למניפסט האפליקציה שלך:

<service
    android:name=".java.MyFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

כמו כן, מומלץ להגדיר ערכי ברירת מחדל כדי להתאים אישית את המראה של התראות. ניתן לציין סמל ברירת מחדל מותאם אישית וצבע ברירת מחדל מותאם אישית שיוחלו בכל פעם שלא מוגדרים ערכים מקבילים במטען ההודעות.

הוסף שורות אלה בתוך תג application כדי להגדיר את סמל ברירת המחדל המותאם אישית ואת הצבע המותאם אישית:

<!-- Set custom default icon. This is used when no icon is set for incoming notification messages.
     See README(https://goo.gl/l4GJaQ) for more. -->
<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_stat_ic_notification" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
     notification message. See README(https://goo.gl/6BKBk7) for more. -->
<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/colorAccent" />

אנדרואיד מציג את סמל ברירת המחדל המותאם אישית עבור

  • כל הודעות ההתראות שנשלחו ממחבר ההתראות .
  • כל הודעת הודעה שאינה מגדירה במפורש את הסמל במטען ההודעות.

אנדרואיד משתמשת בצבע ברירת המחדל המותאם אישית עבור

  • כל הודעות ההתראות שנשלחו ממחבר ההתראות .
  • כל הודעת הודעה שאינה מגדירה במפורש את הצבע במטען ההודעות.

אם לא הוגדר סמל ברירת מחדל מותאם אישית ולא הוגדר סמל במטען ההודעות, אנדרואיד מציג את סמל האפליקציה מעובד בלבן.

עוקף על onMessageReceived

על ידי ביטול השיטה FirebaseMessagingService.onMessageReceived , תוכל לבצע פעולות על סמך אובייקט RemoteMessage שהתקבל ולקבל את נתוני ההודעה:

Kotlin+KTX

override fun onMessageReceived(remoteMessage: RemoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: ${remoteMessage.from}")

    // Check if message contains a data payload.
    if (remoteMessage.data.isNotEmpty()) {
        Log.d(TAG, "Message data payload: ${remoteMessage.data}")

        // Check if data needs to be processed by long running job
        if (needsToBeScheduled()) {
            // For long-running tasks (10 seconds or more) use WorkManager.
            scheduleJob()
        } else {
            // Handle message within 10 seconds
            handleNow()
        }
    }

    // Check if message contains a notification payload.
    remoteMessage.notification?.let {
        Log.d(TAG, "Message Notification Body: ${it.body}")
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
}

Java

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());

        if (/* Check if data needs to be processed by long running job */ true) {
            // For long-running tasks (10 seconds or more) use WorkManager.
            scheduleJob();
        } else {
            // Handle message within 10 seconds
            handleNow();
        }

    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
}

עוקף על onDeletedMessages

במצבים מסוימים, ייתכן ש-FCM לא יעביר הודעה. זה מתרחש כאשר יש יותר מדי הודעות (>100) ממתינות עבור האפליקציה שלך במכשיר מסוים בזמן שהוא מתחבר או אם המכשיר לא התחבר ל-FCM במשך יותר מחודש אחד. במקרים אלה, ייתכן שתקבל התקשרות חוזרת אל FirebaseMessagingService.onDeletedMessages() כאשר מופע האפליקציה מקבל התקשרות חוזרת זו, עליו לבצע סנכרון מלא עם שרת האפליקציה שלך. אם לא שלחת הודעה לאפליקציה במכשיר זה במהלך 4 השבועות האחרונים, FCM לא יתקשר ל- onDeletedMessages() .

טפל בהודעות התראות באפליקציה ברקע

כאשר האפליקציה שלך ברקע, אנדרואיד מפנה הודעות התראה למגש המערכת. הקשה של משתמש על ההודעה פותחת את משגר האפליקציות כברירת מחדל.

זה כולל הודעות שמכילות הן הודעות והן עומס נתונים (וכל ההודעות שנשלחו ממסוף ההודעות). במקרים אלה, ההודעה נמסרת למגש המערכת של המכשיר, ומטען הנתונים נמסר בתוספות של כוונת פעילות המשגר ​​שלך.

לקבלת תובנות לגבי מסירת הודעות לאפליקציה שלך, ראה את לוח המחוונים לדיווח של FCM , שמתעד את מספר ההודעות שנשלחו ונפתחו במכשירי אפל ו-Android, יחד עם נתונים עבור "הופעות" (התראות שנראו על ידי משתמשים) עבור אפליקציות Android.

בנה בקשות לשלוח

לאחר שיצרת נושא, על ידי הרשמה למופעי אפליקציית לקוח לנושא בצד הלקוח או באמצעות ממשק API של השרת , תוכל לשלוח הודעות לנושא. אם זו הפעם הראשונה שאתה בונה בקשות שליחה עבור FCM, עיין במדריך לסביבת השרת שלך ול-FCM לקבלת מידע חשוב על רקע והגדרה.

בלוגיקת השליחה שלך בקצה העורפי, ציין את שם הנושא הרצוי כפי שמוצג:

Node.js

// The topic name can be optionally prefixed with "/topics/".
const topic = 'highScores';

const message = {
  data: {
    score: '850',
    time: '2:45'
  },
  topic: topic
};

// Send a message to devices subscribed to the provided topic.
getMessaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

Java

// The topic name can be optionally prefixed with "/topics/".
String topic = "highScores";

// See documentation on defining a message payload.
Message message = Message.builder()
    .putData("score", "850")
    .putData("time", "2:45")
    .setTopic(topic)
    .build();

// Send a message to the devices subscribed to the provided topic.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);

פִּיתוֹן

# The topic name can be optionally prefixed with "/topics/".
topic = 'highScores'

# See documentation on defining a message payload.
message = messaging.Message(
    data={
        'score': '850',
        'time': '2:45',
    },
    topic=topic,
)

# Send a message to the devices subscribed to the provided topic.
response = messaging.send(message)
# Response is a message ID string.
print('Successfully sent message:', response)

ללכת

// The topic name can be optionally prefixed with "/topics/".
topic := "highScores"

// See documentation on defining a message payload.
message := &messaging.Message{
	Data: map[string]string{
		"score": "850",
		"time":  "2:45",
	},
	Topic: topic,
}

// Send a message to the devices subscribed to the provided topic.
response, err := client.Send(ctx, message)
if err != nil {
	log.Fatalln(err)
}
// Response is a message ID string.
fmt.Println("Successfully sent message:", response)

C#

// The topic name can be optionally prefixed with "/topics/".
var topic = "highScores";

// See documentation on defining a message payload.
var message = new Message()
{
    Data = new Dictionary<string, string>()
    {
        { "score", "850" },
        { "time", "2:45" },
    },
    Topic = topic,
};

// Send a message to the devices subscribed to the provided topic.
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
// Response is a message ID string.
Console.WriteLine("Successfully sent message: " + response);

מנוחה

POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
  "message":{
    "topic" : "foo-bar",
    "notification" : {
      "body" : "This is a Firebase Cloud Messaging Topic Message!",
      "title" : "FCM Message"
      }
   }
}

פקודת cURL:

curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
  "message": {
    "topic" : "foo-bar",
    "notification": {
      "body": "This is a Firebase Cloud Messaging Topic Message!",
      "title": "FCM Message"
    }
  }
}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

כדי לשלוח הודעה לשילוב של נושאים, ציין תנאי , שהוא ביטוי בוליאני המציין את נושאי היעד. לדוגמה, התנאי הבא ישלח הודעות למכשירים המנויים על TopicA ועל TopicB או TopicC :

"'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)"

FCM מעריך תחילה תנאים בסוגריים, ולאחר מכן מעריך את הביטוי משמאל לימין. בביטוי שלמעלה, משתמש שנרשם לאף נושא בודד אינו מקבל את ההודעה. כמו כן, משתמש שאינו מנוי ל- TopicA אינו מקבל את ההודעה. השילובים האלה אכן מקבלים את זה:

  • TopicA ונושא TopicB
  • TopicA ו- TopicC

אתה יכול לכלול עד חמישה נושאים בביטוי המותנה שלך.

כדי לשלוח לתנאי:

Node.js

// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
const condition = '\'stock-GOOG\' in topics || \'industry-tech\' in topics';

// See documentation on defining a message payload.
const message = {
  notification: {
    title: '$FooCorp up 1.43% on the day',
    body: '$FooCorp gained 11.80 points to close at 835.67, up 1.43% on the day.'
  },
  condition: condition
};

// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
getMessaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

Java

// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
String condition = "'stock-GOOG' in topics || 'industry-tech' in topics";

// See documentation on defining a message payload.
Message message = Message.builder()
    .setNotification(Notification.builder()
        .setTitle("$GOOG up 1.43% on the day")
        .setBody("$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.")
        .build())
    .setCondition(condition)
    .build();

// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);

פִּיתוֹן

# Define a condition which will send to devices which are subscribed
# to either the Google stock or the tech industry topics.
condition = "'stock-GOOG' in topics || 'industry-tech' in topics"

# See documentation on defining a message payload.
message = messaging.Message(
    notification=messaging.Notification(
        title='$GOOG up 1.43% on the day',
        body='$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
    ),
    condition=condition,
)

# Send a message to devices subscribed to the combination of topics
# specified by the provided condition.
response = messaging.send(message)
# Response is a message ID string.
print('Successfully sent message:', response)

ללכת

// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
condition := "'stock-GOOG' in topics || 'industry-tech' in topics"

// See documentation on defining a message payload.
message := &messaging.Message{
	Data: map[string]string{
		"score": "850",
		"time":  "2:45",
	},
	Condition: condition,
}

// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
response, err := client.Send(ctx, message)
if err != nil {
	log.Fatalln(err)
}
// Response is a message ID string.
fmt.Println("Successfully sent message:", response)

C#

// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
var condition = "'stock-GOOG' in topics || 'industry-tech' in topics";

// See documentation on defining a message payload.
var message = new Message()
{
    Notification = new Notification()
    {
        Title = "$GOOG up 1.43% on the day",
        Body = "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.",
    },
    Condition = condition,
};

// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
// Response is a message ID string.
Console.WriteLine("Successfully sent message: " + response);

מנוחה

POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
   "message":{
    "condition": "'dogs' in topics || 'cats' in topics",
    "notification" : {
      "body" : "This is a Firebase Cloud Messaging Topic Message!",
      "title" : "FCM Message",
    }
  }
}

פקודת cURL:

curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
  "notification": {
    "title": "FCM Message",
    "body": "This is a Firebase Cloud Messaging Topic Message!",
  },
  "condition": "'dogs' in topics || 'cats' in topics"
}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

הצעדים הבאים

  • אתה יכול להשתמש בשרת שלך כדי לרשום מופעי אפליקציה של לקוח לנושאים ולבצע משימות ניהול אחרות. ראה ניהול מנויי נושאים בשרת .