এই নির্দেশিকাটি বর্ণনা করে কিভাবে আপনার মোবাইল এবং ওয়েব ক্লায়েন্ট অ্যাপগুলিতে Firebase Cloud Messaging সেট আপ করবেন যাতে আপনি নির্ভরযোগ্যভাবে বার্তা গ্রহণ করতে পারেন।
একবার আপনার ক্লায়েন্ট অ্যাপটি কোনও ডিভাইসে ইনস্টল হয়ে গেলে, এটি FCM APNs ইন্টারফেসের মাধ্যমে বার্তা গ্রহণ করতে পারে। আপনি অবিলম্বে নোটিফিকেশন কম্পোজার ব্যবহার করে ব্যবহারকারীর অংশগুলিতে বিজ্ঞপ্তি পাঠানো শুরু করতে পারেন, অথবা আপনার অ্যাপ্লিকেশন সার্ভারে তৈরি বার্তাগুলি।
সতর্কতা বিজ্ঞপ্তিগুলি পরিচালনা করুন
FCM অ্যাপল অ্যাপগুলিকে লক্ষ্য করে সমস্ত বার্তা APN-এর মাধ্যমে সরবরাহ করে। UNUserNotificationCenter
ব্যবহার করে APN-এর বিজ্ঞপ্তিগুলি গ্রহণ করার বিষয়ে আরও জানতে, Handling Notifications and Notification-related Actions- এর উপর Apple-এর ডকুমেন্টেশন দেখুন।
FCM থেকে ডিসপ্লে নোটিফিকেশন পেতে আপনাকে UNUserNotificationCenter ডেলিগেট সেট করতে হবে এবং উপযুক্ত ডেলিগেট পদ্ধতি প্রয়োগ করতে হবে।
সুইফট
extension AppDelegate: UNUserNotificationCenterDelegate {
// 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.
if #available(iOS 14.0, *) {
return [.list, .banner, .sound]
} else {
return [.alert, .sound]
}
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse) async {
let userInfo = response.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)
}
}
অবজেক্টিভ-সি
// 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
// Note: UNNotificationPresentationOptionAlert has been deprecated.
if (@available(iOS 14.0, *)) {
completionHandler(UNNotificationPresentationOptionList |
UNNotificationPresentationOptionBanner |
UNNotificationPresentationOptionSound);
} else {
completionHandler(UNNotificationPresentationOptionAlert |
UNNotificationPresentationOptionSound);
}
}
// Handle notification messages after display notification is tapped by the user.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)(void))completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
if (userInfo[kGCMMessageIDKey]) {
NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
}
// With swizzling disabled you must let Messaging know about the message, for Analytics
// [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
// Print full message.
NSLog(@"%@", userInfo);
completionHandler();
}
আপনার বিজ্ঞপ্তিতে কাস্টম অ্যাকশন যোগ করতে চাইলে, নোটিফিকেশন পেলোডে click_action
প্যারামিটার সেট করুন। APN পেলোডে category
কী-এর জন্য আপনি যে মানটি ব্যবহার করবেন তা ব্যবহার করুন। কাস্টম অ্যাকশনগুলি ব্যবহার করার আগে অবশ্যই নিবন্ধিত হতে হবে। আরও তথ্যের জন্য, অ্যাপলের স্থানীয় এবং দূরবর্তী বিজ্ঞপ্তি প্রোগ্রামিং গাইড দেখুন।
আপনার অ্যাপে বার্তা সরবরাহের অন্তর্দৃষ্টির জন্য, FCM রিপোর্টিং ড্যাশবোর্ডটি দেখুন, যা অ্যাপল এবং অ্যান্ড্রয়েড ডিভাইসে প্রেরিত এবং খোলা বার্তার সংখ্যা রেকর্ড করে, সাথে অ্যান্ড্রয়েড অ্যাপের জন্য "ইমপ্রেশন" (ব্যবহারকারীদের দ্বারা দেখা বিজ্ঞপ্তি) এর ডেটাও রেকর্ড করে।
নীরব পুশ বিজ্ঞপ্তিগুলি পরিচালনা করুন
content-available
কী (APN-এর content-available
সমতুল্য) ব্যবহার করে বার্তা পাঠানোর সময়, বার্তাগুলি নীরব বিজ্ঞপ্তি হিসাবে বিতরণ করা হবে, ব্যাকগ্রাউন্ড ডেটা রিফ্রেশের মতো কাজের জন্য আপনার অ্যাপটিকে ব্যাকগ্রাউন্ডে জাগিয়ে তুলবে। ফোরগ্রাউন্ড বিজ্ঞপ্তিগুলির বিপরীতে, এই বিজ্ঞপ্তিগুলি application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
পদ্ধতি ব্যবহার করে পরিচালনা করতে হবে।
দেখানো পদ্ধতিতে application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
প্রয়োগ করুন:
সুইফট
@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 message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
print("Call exportDeliveryMetricsToBigQuery() from AppDelegate")
Messaging.serviceExtension().exportDeliveryMetricsToBigQuery(withMessageInfo: 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);
}
অ্যাপল প্ল্যাটফর্মগুলি ব্যাকগ্রাউন্ড নোটিফিকেশন সরবরাহের গ্যারান্টি দেয় না। ব্যাকগ্রাউন্ড নোটিফিকেশন ব্যর্থ হতে পারে এমন পরিস্থিতি সম্পর্কে জানতে, অ্যাপলের ডক্স " আপনার অ্যাপে ব্যাকগ্রাউন্ড আপডেট পুশ করা" দেখুন।
বিজ্ঞপ্তি বার্তা পেলোড ব্যাখ্যা করুন
বিজ্ঞপ্তি বার্তার পেলোড হল কী এবং মানগুলির একটি অভিধান। APN-এর মাধ্যমে প্রেরিত বিজ্ঞপ্তি বার্তাগুলির APN-এর পেলোড ফর্ম্যাট নিম্নরূপ:
{
"aps" : {
"alert" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
},
"badge" : 1,
},
"customKey" : "customValue"
}
মেথড সুইজলিং অক্ষম থাকা অবস্থায় বার্তা পরিচালনা করুন
ডিফল্টরূপে, যদি আপনি আপনার অ্যাপের অ্যাপ ডেলিগেট ক্লাসটি UNUserNotificationCenter
এবং Messaging
ডেলিগেট প্রোপার্টিগুলিতে বরাদ্দ করেন, তাহলে FCM আপনার অ্যাপ ডেলিগেট ক্লাসটিকে স্বয়ংক্রিয়ভাবে ডিভাইসের FCM টোকেনের সাথে সংযুক্ত করার জন্য সুইজল করবে এবং বিজ্ঞপ্তি-প্রাপ্ত ইভেন্টগুলিকে Analytics এ প্রেরণ করবে। যদি আপনি স্পষ্টভাবে মেথড সুইজলিং অক্ষম করেন, যদি আপনি একটি SwiftUI অ্যাপ তৈরি করেন, অথবা যদি আপনি উভয় ডেলিগেটের জন্য একটি পৃথক ক্লাস ব্যবহার করেন, তাহলে আপনাকে এই দুটি কাজ ম্যানুয়ালি করতে হবে।
ডিভাইসের APN টোকেনের সাথে FCM টোকেন সংযুক্ত করতে, apnsToken
প্রপার্টি ব্যবহার করে আপনার অ্যাপ ডেলিগেটের টোকেন রিফ্রেশ হ্যান্ডলারের Messaging
ক্লাসে APN টোকেনটি পাস করুন।
সুইফট
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken;
}
অবজেক্টিভ-সি
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[FIRMessaging messaging].APNSToken = deviceToken;
}
Analytics বিজ্ঞপ্তি প্রাপ্তির তথ্য পাঠাতে, appDidReceiveMessage(_:)
পদ্ধতিটি ব্যবহার করুন।
সুইফট
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)
}
অবজেক্টিভ-সি
- (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);
}