Apple প্ল্যাটফর্মে একাধিক ডিভাইসে বার্তা পাঠান

একাধিক ডিভাইসে একটি বার্তা লক্ষ্য করতে, টপিক মেসেজিং ব্যবহার করুন। এই বৈশিষ্ট্যটি আপনাকে একটি নির্দিষ্ট বিষয় বেছে নেওয়া একাধিক ডিভাইসে একটি বার্তা পাঠাতে দেয়৷

এই টিউটোরিয়ালটি FCM-এর জন্য অ্যাডমিন SDK বা REST API ব্যবহার করে আপনার অ্যাপ সার্ভার থেকে বিষয় বার্তা পাঠানো এবং একটি Apple অ্যাপে সেগুলি গ্রহণ ও পরিচালনা করার উপর ফোকাস করে। এই পৃষ্ঠাটি সেটআপ থেকে যাচাইকরণ পর্যন্ত এটি অর্জনের সমস্ত পদক্ষেপের তালিকা করে — তাই আপনি যদি FCM-এর জন্য একটি Apple ক্লায়েন্ট অ্যাপ সেট আপ করে থাকেন বা আপনার প্রথম বার্তা পাঠানোর পদক্ষেপগুলির মাধ্যমে কাজ করে থাকেন তবে এটি আপনার ইতিমধ্যে সম্পন্ন করা পদক্ষেপগুলি কভার করতে পারে৷

আপনার Apple প্রকল্পে Firebase যোগ করুন

আপনি যদি ইতিমধ্যে আপনার অ্যাপের জন্য অন্যান্য Firebase বৈশিষ্ট্যগুলি সক্ষম করে থাকেন তবে এই বিভাগে আপনি যে কাজগুলি সম্পন্ন করেছেন তা কভার করে৷ FCM-এর জন্য বিশেষভাবে, আপনাকে আপনার APN-এর প্রমাণীকরণ কী আপলোড করতে হবে এবং দূরবর্তী বিজ্ঞপ্তিগুলির জন্য নিবন্ধন করতে হবে

পূর্বশর্ত

  • নিম্নলিখিত ইনস্টল করুন:

    • Xcode 14.1 বা তার পরে
  • নিশ্চিত করুন যে আপনার প্রকল্প এই প্রয়োজনীয়তাগুলি পূরণ করে:

    • আপনার প্রজেক্টকে অবশ্যই এই প্ল্যাটফর্ম সংস্করণগুলিকে লক্ষ্য করতে হবে বা পরবর্তীতে:
      • iOS 11
      • macOS 10.13
      • টিভিওএস 12
      • watchOS 6
  • আপনার অ্যাপ চালানোর জন্য একটি শারীরিক অ্যাপল ডিভাইস সেট আপ করুন এবং এই কাজগুলি সম্পূর্ণ করুন:

আপনার যদি ইতিমধ্যে একটি Xcode প্রকল্প না থাকে এবং আপনি শুধুমাত্র একটি Firebase পণ্য ব্যবহার করে দেখতে চান, তাহলে আপনি আমাদের কুইকস্টার্ট নমুনাগুলির একটি ডাউনলোড করতে পারেন৷

একটি ফায়ারবেস প্রকল্প তৈরি করুন

আপনি আপনার Apple অ্যাপে Firebase যোগ করার আগে, আপনার অ্যাপের সাথে সংযোগ করার জন্য আপনাকে একটি Firebase প্রকল্প তৈরি করতে হবে। Firebase প্রকল্পগুলি সম্পর্কে আরও জানতে Firebase প্রকল্পগুলি বুঝতে দেখুন৷

Firebase এর সাথে আপনার অ্যাপ নিবন্ধন করুন

আপনার Apple অ্যাপে Firebase ব্যবহার করতে, আপনাকে আপনার Firebase প্রকল্পের সাথে আপনার অ্যাপটি নিবন্ধন করতে হবে। আপনার অ্যাপ নিবন্ধন করাকে প্রায়ই আপনার প্রকল্পে আপনার অ্যাপকে "সংযোজন" বলা হয়।

  1. ফায়ারবেস কনসোলে যান।

  2. প্রকল্প ওভারভিউ পৃষ্ঠার কেন্দ্রে, সেটআপ ওয়ার্কফ্লো চালু করতে iOS+ আইকনে ক্লিক করুন।

    আপনি যদি ইতিমধ্যেই আপনার Firebase প্রকল্পে একটি অ্যাপ যোগ করে থাকেন, তাহলে প্ল্যাটফর্মের বিকল্পগুলি প্রদর্শন করতে অ্যাপ যোগ করুন- এ ক্লিক করুন।

  3. বান্ডেল আইডি ফিল্ডে আপনার অ্যাপের বান্ডেল আইডি লিখুন।

  4. (ঐচ্ছিক) অন্যান্য অ্যাপের তথ্য লিখুন: অ্যাপের ডাকনাম এবং অ্যাপ স্টোর আইডি

  5. রেজিস্টার অ্যাপে ক্লিক করুন।

একটি ফায়ারবেস কনফিগারেশন ফাইল যোগ করুন

  1. আপনার Firebase Apple প্ল্যাটফর্ম কনফিগার ফাইল ( GoogleService-Info.plist ) পেতে ডাউনলোড GoogleService-Info.plist-এ ক্লিক করুন।

  2. আপনার কনফিগার ফাইলটি আপনার Xcode প্রকল্পের রুটে সরান। অনুরোধ করা হলে, সমস্ত টার্গেটে কনফিগার ফাইল যোগ করতে নির্বাচন করুন।

আপনার প্রোজেক্টে একাধিক বান্ডিল আইডি থাকলে, আপনাকে অবশ্যই প্রতিটি বান্ডিল আইডিকে Firebase কনসোলে একটি নিবন্ধিত অ্যাপের সাথে সংযুক্ত করতে হবে যাতে প্রতিটি অ্যাপের নিজস্ব GoogleService-Info.plist ফাইল থাকতে পারে।

আপনার অ্যাপে Firebase SDK যোগ করুন

ফায়ারবেস নির্ভরতা ইনস্টল এবং পরিচালনা করতে সুইফট প্যাকেজ ম্যানেজার ব্যবহার করুন।

  1. Xcode-এ, আপনার অ্যাপ প্রকল্প খোলার সাথে, ফাইল > প্যাকেজ যোগ করুন- এ নেভিগেট করুন।
  2. অনুরোধ করা হলে, Firebase Apple প্ল্যাটফর্ম SDK সংগ্রহস্থল যোগ করুন:
  3.   https://github.com/firebase/firebase-ios-sdk.git
  4. ফায়ারবেস ক্লাউড মেসেজিং লাইব্রেরি বেছে নিন।
  5. আপনার লক্ষ্যের বিল্ড সেটিংসের অন্যান্য লিঙ্কার ফ্ল্যাগ বিভাগে -ObjC পতাকা যোগ করুন।
  6. Firebase ক্লাউড মেসেজিংয়ের সর্বোত্তম অভিজ্ঞতার জন্য, আমরা আপনার Firebase প্রকল্পে Google Analytics সক্ষম করার এবং আপনার অ্যাপে Google Analytics-এর জন্য Firebase SDK যোগ করার পরামর্শ দিই। আপনি IDFA সংগ্রহ ছাড়াই অথবা IDFA সংগ্রহের মাধ্যমে লাইব্রেরি নির্বাচন করতে পারেন।
  7. শেষ হয়ে গেলে, Xcode স্বয়ংক্রিয়ভাবে পটভূমিতে আপনার নির্ভরতাগুলি সমাধান এবং ডাউনলোড করা শুরু করবে।

আপনার APN প্রমাণীকরণ কী আপলোড করুন

Firebase-এ আপনার APN-এর প্রমাণীকরণ কী আপলোড করুন। যদি আপনার কাছে ইতিমধ্যে একটি APN-এর প্রমাণীকরণ কী না থাকে, তাহলে Apple বিকাশকারী সদস্য কেন্দ্রে একটি তৈরি করা নিশ্চিত করুন৷

  1. Firebase কনসোলে আপনার প্রকল্পের ভিতরে, গিয়ার আইকন নির্বাচন করুন, প্রকল্প সেটিংস নির্বাচন করুন এবং তারপরে ক্লাউড মেসেজিং ট্যাবটি নির্বাচন করুন৷

  2. iOS অ্যাপ কনফিগারেশনের অধীনে APNs প্রমাণীকরণ কী- এ, আপলোড বোতামে ক্লিক করুন।

  3. আপনি যেখানে আপনার কী সংরক্ষণ করেছেন সেখানে ব্রাউজ করুন, এটি নির্বাচন করুন এবং খুলুন ক্লিক করুন। কীটির জন্য কী আইডি যোগ করুন ( অ্যাপল বিকাশকারী সদস্য কেন্দ্রে উপলব্ধ) এবং আপলোড ক্লিক করুন।

আপনার অ্যাপে Firebase চালু করুন

আপনাকে আপনার অ্যাপ্লিকেশনে ফায়ারবেস ইনিশিয়ালাইজেশন কোড যোগ করতে হবে। Firebase মডিউল আমদানি করুন এবং দেখানো হিসাবে একটি ভাগ করা উদাহরণ কনফিগার করুন:

  1. আপনার UIApplicationDelegateFirebaseCore মডিউল আমদানি করুন, সেইসাথে আপনার অ্যাপ প্রতিনিধি যে কোনো Firebase মডিউল ব্যবহার করেন। উদাহরণস্বরূপ, ক্লাউড ফায়ারস্টোর এবং প্রমাণীকরণ ব্যবহার করতে:

    সুইফটইউআই

    import SwiftUI
    import FirebaseCore
    import FirebaseFirestore
    import FirebaseAuth
    // ...
          

    সুইফট

    import FirebaseCore
    import FirebaseFirestore
    import FirebaseAuth
    // ...
          

    উদ্দেশ্য গ

    @import FirebaseCore;
    @import FirebaseFirestore;
    @import FirebaseAuth;
    // ...
          
  2. আপনার অ্যাপ প্রতিনিধির application(_:didFinishLaunchingWithOptions:) পদ্ধতিতে একটি FirebaseApp শেয়ার করা উদাহরণ কনফিগার করুন:

    সুইফটইউআই

    // Use Firebase library to configure APIs
    FirebaseApp.configure()

    সুইফট

    // Use Firebase library to configure APIs
    FirebaseApp.configure()

    উদ্দেশ্য গ

    // Use Firebase library to configure APIs
    [FIRApp configure];
  3. আপনি যদি SwiftUI ব্যবহার করেন, তাহলে আপনাকে অবশ্যই একটি অ্যাপ্লিকেশন ডেলিগেট তৈরি করতে হবে এবং UIApplicationDelegateAdaptor বা NSApplicationDelegateAdaptor এর মাধ্যমে আপনার App স্ট্রাকটে এটি সংযুক্ত করতে হবে। আপনাকে অবশ্যই অ্যাপ ডেলিগেট সুইজলিং অক্ষম করতে হবে। আরও তথ্যের জন্য, SwiftUI নির্দেশাবলী দেখুন।

    সুইফটইউআই

    @main
    struct YourApp: App {
      // register app delegate for Firebase setup
      @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
    
      var body: some Scene {
        WindowGroup {
          NavigationView {
            ContentView()
          }
        }
      }
    }
          

দূরবর্তী বিজ্ঞপ্তির জন্য নিবন্ধন করুন

হয় স্টার্টআপে, বা আপনার অ্যাপ্লিকেশন প্রবাহের পছন্দসই পয়েন্টে, দূরবর্তী বিজ্ঞপ্তিগুলির জন্য আপনার অ্যাপ নিবন্ধন করুন৷ কল registerForRemoteNotifications যেমন দেখানো হয়েছে:

সুইফট


UNUserNotificationCenter.current().delegate = self

let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
  options: authOptions,
  completionHandler: { _, _ in }
)

application.registerForRemoteNotifications()

উদ্দেশ্য গ


[UNUserNotificationCenter currentNotificationCenter].delegate = self;
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
    UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter]
    requestAuthorizationWithOptions:authOptions
    completionHandler:^(BOOL granted, NSError * _Nullable error) {
      // ...
    }];

[application registerForRemoteNotifications];

একটি বিষয় ক্লায়েন্ট অ্যাপ্লিকেশন সদস্যতা

ক্লায়েন্ট অ্যাপগুলি বিদ্যমান যেকোনো বিষয়ের সদস্যতা নিতে পারে, অথবা তারা একটি নতুন বিষয় তৈরি করতে পারে। যখন একটি ক্লায়েন্ট অ্যাপ একটি নতুন বিষয়ের নাম (যেটি আপনার ফায়ারবেস প্রকল্পের জন্য ইতিমধ্যে বিদ্যমান নেই) সাবস্ক্রাইব করে, তখন সেই নামের একটি নতুন বিষয় এফসিএম-এ তৈরি হয় এবং যেকোনো ক্লায়েন্ট পরবর্তীতে এটিতে সদস্যতা নিতে পারে।

একটি বিষয়ের সদস্যতা নিতে, আপনার অ্যাপ্লিকেশনের প্রধান থ্রেড থেকে সদস্যতা পদ্ধতিতে কল করুন (FCM থ্রেড-নিরাপদ নয়)। সদস্যতা অনুরোধ প্রাথমিকভাবে ব্যর্থ হলে, FCM স্বয়ংক্রিয়ভাবে পুনরায় চেষ্টা করে। যে ক্ষেত্রে সাবস্ক্রিপশন সম্পূর্ণ করা যায় না, সাবস্ক্রিপশন একটি ত্রুটি ছুঁড়ে দেয় যা আপনি দেখানো হিসাবে একটি সম্পূর্ণ হ্যান্ডলারে ধরতে পারেন:

সুইফট

Messaging.messaging().subscribe(toTopic: "weather") { error in
  print("Subscribed to weather topic")
}

উদ্দেশ্য গ

[[FIRMessaging messaging] subscribeToTopic:@"weather"
                                completion:^(NSError * _Nullable error) {
  NSLog(@"Subscribed to weather topic");
}];

এই কলটি FCM ব্যাকএন্ডে একটি অ্যাসিঙ্ক্রোনাস অনুরোধ করে এবং প্রদত্ত বিষয়ে ক্লায়েন্টকে সাবস্ক্রাইব করে। subscribeToTopic:topic এ কল করার আগে নিশ্চিত করুন যে ক্লায়েন্ট অ্যাপ ইন্সট্যান্স ইতিমধ্যেই callback didReceiveRegistrationToken এর মাধ্যমে একটি রেজিস্ট্রেশন টোকেন পেয়েছে।

প্রতিবার অ্যাপটি শুরু হলে, FCM নিশ্চিত করে যে সমস্ত অনুরোধ করা বিষয় সাবস্ক্রাইব করা হয়েছে। আনসাবস্ক্রাইব করতে, unsubscribeFromTopic:topic কল করুন এবং পটভূমিতে বিষয় থেকে FCM আনসাবস্ক্রাইব করুন।

বিষয় বার্তা গ্রহণ এবং পরিচালনা

FCM অন্যান্য ডাউনস্ট্রিম বার্তাগুলির মতোই বিষয় বার্তাগুলি সরবরাহ করে৷

application(_:didReceiveRemoteNotification:fetchCompletionHandler:) যেমন দেখানো হয়েছে:

সুইফট

func application(_ application: UIApplication,
                 didReceiveRemoteNotification userInfo: [AnyHashable: Any]) async
  -> UIBackgroundFetchResult {
  // If you are receiving a notification message while your app is in the background,
  // this callback will not be fired till the user taps on the notification launching the application.
  // TODO: Handle data of notification

  // With swizzling disabled you must let Messaging know about the message, for Analytics
  // Messaging.messaging().appDidReceiveMessage(userInfo)

  // Print message ID.
  if let messageID = userInfo[gcmMessageIDKey] {
    print("Message ID: \(messageID)")
  }

  // Print full message.
  print(userInfo)

  return UIBackgroundFetchResult.newData
}

উদ্দেশ্য গ

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  // If you are receiving a notification message while your app is in the background,
  // this callback will not be fired till the user taps on the notification launching the application.
  // TODO: Handle data of notification

  // With swizzling disabled you must let Messaging know about the message, for Analytics
  // [[FIRMessaging messaging] appDidReceiveMessage:userInfo];

  // ...

  // Print full message.
  NSLog(@"%@", userInfo);

  completionHandler(UIBackgroundFetchResultNewData);
}

অনুরোধ পাঠান তৈরি করুন

আপনি একটি বিষয় তৈরি করার পরে, হয় ক্লায়েন্ট সাইডের বিষয়ে বা সার্ভার 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);
  });

জাভা

// 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)

সি#

// 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);
  });

জাভা

// 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)

সি#

// 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

পরবর্তী পদক্ষেপ

  • আপনি বিষয়গুলিতে ক্লায়েন্ট অ্যাপের দৃষ্টান্তগুলি সাবস্ক্রাইব করতে এবং অন্যান্য পরিচালনার কাজগুলি সম্পাদন করতে আপনার সার্ভার ব্যবহার করতে পারেন। সার্ভারে বিষয় সদস্যতা পরিচালনা দেখুন।