| প্ল্যাটফর্ম বেছে নিন: | iOS+ Android ওয়েব Flutter Unity C++ |
কোনও ডিভাইসে আপনার ক্লায়েন্ট অ্যাপ ইনস্টল করা হয়ে গেলে, এটি FCM APNs ইন্টারফেসের মাধ্যমে মেসেজ পেতে পারে। আপনি Firebase কনসোলে বিজ্ঞপ্তি কম্পোজার ব্যবহার করে অথবা আপনার অ্যাপ্লিকেশন সার্ভারে তৈরি করা মেসেজের মাধ্যমে ব্যবহারকারীর বিভিন্ন সেগমেন্টে অবিলম্বে বিজ্ঞপ্তি পাঠানো শুরু করতে পারেন।
সতর্কতামূলক বিজ্ঞপ্তি ম্যানেজ করা
FCM APNs-এর মাধ্যমে Apple অ্যাপের জন্য তৈরি করা সব মেসেজ ডেলিভার করে। UNUserNotificationCenter ব্যবহার করে APNs বিজ্ঞপ্তি পাওয়া সম্পর্কে
আরও জানতে, বিজ্ঞপ্তি ও বিজ্ঞপ্তি-সম্পর্কিত অ্যাকশন ম্যানেজ করা
সম্পর্কে Apple-এর ডকুমেন্টেশন দেখুন।
FCM থেকে ডিসপ্লে বিজ্ঞপ্তি পেতে আপনাকে অবশ্যই UNUserNotificationCenter delegate সেট করতে হবে এবং উপযুক্ত ডেলিগেট পদ্ধতি প্রয়োগ করতে হবে।
Swift
// Receive displayed notifications for iOS 10+ devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification) async
-> UNNotificationPresentationOptions {
let userInfo = notification.request.content.userInfo
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// ...
// Print full message.
print(userInfo)
// Change this to your preferred presentation option
// Note: UNNotificationPresentationOptions.alert has been deprecated.
return [.list, .banner, .sound]
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse) async {
let userInfo = response.notification.request.content.userInfo
// ...
// Print full message.
print(userInfo)
}
Objective-C
// Receive displayed notifications for iOS 10+ devices.
// Handle incoming notification messages while app is in the foreground.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
NSDictionary *userInfo = notification.request.content.userInfo;
// With swizzling disabled you must let Messaging know about the message, for Analytics
// [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
// Print full message.
NSLog(@"%@", userInfo);
// Change this to your preferred presentation option
completionHandler(UNNotificationPresentationOptionList |
UNNotificationPresentationOptionBanner |
UNNotificationPresentationOptionSound);
}
- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
NSLog(@"FCM registration token: %@", fcmToken);
// Notify about received token.
NSDictionary *dataDict = [NSDictionary dictionaryWithObject:fcmToken forKey:@"token"];
[[NSNotificationCenter defaultCenter] postNotificationName:
@"FCMToken" object:nil userInfo:dataDict];
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
- (void)logFCMToken {
NSString *fcmToken = [FIRMessaging messaging].FCMToken;
NSLog(@"Local FCM registration token: %@", fcmToken);
NSString* displayToken = [NSString stringWithFormat:@"Logged FCM token: %@", fcmToken];
[[FIRMessaging messaging] tokenWithCompletion:^(NSString * _Nullable token, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Error fetching the remote FCM registration token: %@", error);
} else {
NSLog(@"Remote FCM registration token: %@", token);
NSString* message =
[NSString stringWithFormat:@"FCM registration token: %@", token];
// display message
NSLog(@"%@", message);
}
}];
NSLog(@"%@", displayToken);
}
- (void)subsribeToTopic {
[[FIRMessaging messaging] subscribeToTopic:@"weather"
completion:^(NSError * _Nullable error) {
NSLog(@"Subscribed to weather topic");
}];
}
@end
আপনার বিজ্ঞপ্তিতে কাস্টম অ্যাকশন যোগ করতে চাইলে, বিজ্ঞপ্তি
পে-লোড-এ click_action
প্যারামিটার সেট করুন।
APNs পেলোডের category কী-এর জন্য আপনি যে ভ্যালু ব্যবহার করবেন সেটিই ব্যবহার করুন।
কাস্টম অ্যাকশন ব্যবহার করার আগে রেজিস্টার করতে হবে। আরও
তথ্যের জন্য, Apple-এর
স্থানীয় ও রিমোট বিজ্ঞপ্তি প্রোগ্রামিং গাইড দেখুন।
আপনার অ্যাপে মেসেজ ডেলিভারি সংক্রান্ত ইনসাইট পেতে, Firebase কনসোলে DevOps ও এনগেজমেন্ট > মেসেজিং > রিপোর্ট ড্যাশবোর্ডে যান। এই ড্যাশবোর্ড Apple ও Android ডিভাইসে পাঠানো ও খোলা মেসেজের সংখ্যা রেকর্ড করে। এর সাথে Android অ্যাপের জন্য "ইম্প্রেশন" (ব্যবহারকারীদের দেখা বিজ্ঞপ্তি) সংক্রান্ত ডেটাও রেকর্ড করে।
সাইলেন্ট পুশ বিজ্ঞপ্তি ম্যানেজ করা
content-available কী (APNs-এর
content-available-এর সমতুল্য) ব্যবহার করে মেসেজ পাঠানোর সময়, মেসেজগুলি সাইলেন্ট বিজ্ঞপ্তি হিসেবে ডেলিভার করা হবে,
ব্যাকগ্রাউন্ড ডেটা রিফ্রেশ করার মতো টাস্কের জন্য ব্যাকগ্রাউন্ডে আপনার অ্যাপকে জাগিয়ে তুলবে।
ফোরগ্রাউন্ড বিজ্ঞপ্তির মতো, এই বিজ্ঞপ্তিগুলি অবশ্যই
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
পদ্ধতি ব্যবহার করে ম্যানেজ করতে হবে।
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
এভাবে প্রয়োগ করুন:
Swift
@MainActor
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 full message.
print(userInfo)
print("Call exportDeliveryMetricsToBigQuery() from AppDelegate")
Messaging.serviceExtension().exportDeliveryMetricsToBigQuery(withMessageInfo: userInfo)
return UIBackgroundFetchResult.newData
}
Objective-C
- (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 until 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);
}
Apple প্ল্যাটফর্ম ব্যাকগ্রাউন্ড বিজ্ঞপ্তি ডেলিভার করার গ্যারান্টি দেয় না। ব্যাকগ্রাউন্ড বিজ্ঞপ্তি কাজ না করার কারণগুলি সম্পর্কে জানতে, Apple-এর আপনার অ্যাপে ব্যাকগ্রাউন্ড আপডেট পুশ করা সংক্রান্ত ডকুমেন্ট দেখুন।
বিজ্ঞপ্তি মেসেজ পেলোড ব্যাখ্যা করা
বিজ্ঞপ্তি মেসেজের পেলোড হল কী ও ভ্যালুর একটি অভিধান। APNs-এর মাধ্যমে পাঠানো বিজ্ঞপ্তি মেসেজে নিম্নলিখিত APNs পেলোড ফর্ম্যাট থাকে:
{
"aps" : {
"alert" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
},
"badge" : 1,
},
"customKey" : "customValue"
}
মেথড সুইজলিং বন্ধ করা আছে এমন মেসেজ ম্যানেজ করা
ডিফল্ট হিসেবে, আপনি যদি নিজের অ্যাপের অ্যাপ ডেলিগেট ক্লাসকে
UNUserNotificationCenter এবং Messaging ডেলিগেট প্রপার্টিতে অ্যাসাইন করেন, তাহলে FCM
আপনার অ্যাপ ডেলিগেট ক্লাসকে সোয়াজল করবে যাতে আপনার
FCM টোকেনকে ডিভাইসের APNs টোকেনের সাথে অটোমেটিক অ্যাসোসিয়েট করা যায় এবং Analytics-এ বিজ্ঞপ্তি পাওয়ার
ইভেন্ট পাস করা যায়। আপনি যদি স্পষ্টভাবে মেথড সুইজল বন্ধ করে দেন, আপনি যদি
SwiftUI অ্যাপ তৈরি করেন অথবা আপনি যদি কোনও ডেলিগেটের জন্য আলাদা ক্লাস ব্যবহার করেন, তাহলে আপনাকে
এই দুটি কাজই ম্যানুয়ালি করতে হবে।
ডিভাইস APNs টোকেনের সাথে FCM টোকেন অ্যাসোসিয়েট করতে, আপনার অ্যাপ ডেলিগেটের
টোকেন রিফ্রেশ হ্যান্ডলার
ব্যবহার করে Messaging ক্লাসে APNs
টোকেন পাস করুন
apnsToken প্রপার্টি।
Swift
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken;
}
Objective-C
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[FIRMessaging messaging].APNSToken = deviceToken;
}
Analytics-কে বিজ্ঞপ্তি প্রাপ্তির তথ্য পাস করতে, appDidReceiveMessage(_:) পদ্ধতি ব্যবহার করুন।
Swift
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
Messaging.messaging().appDidReceiveMessage(userInfo)
// Change this to your preferred presentation option
completionHandler([[.alert, .sound]])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
Messaging.messaging().appDidReceiveMessage(userInfo)
completionHandler()
}
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Messaging.messaging().appDidReceiveMessage(userInfo)
completionHandler(.noData)
}
Objective-C
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
NSDictionary *userInfo = notification.request.content.userInfo;
[[FIRMessaging messaging] appDidReceiveMessage:userInfo];
// Change this to your preferred presentation option
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)(void))completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
[[FIRMessaging messaging] appDidReceiveMessage:userInfo];
completionHandler();
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
[[FIRMessaging messaging] appDidReceiveMessage:userInfo];
completionHandler(UIBackgroundFetchResultNoData);
}