এই নির্দেশিকা বর্ণনা করে কিভাবে আপনার মোবাইল এবং ওয়েব ক্লায়েন্ট অ্যাপে Firebase Cloud Messaging সেট আপ করবেন যাতে আপনি নির্ভরযোগ্যভাবে বার্তা পেতে পারেন।
একবার আপনার ক্লায়েন্ট অ্যাপটি একটি ডিভাইসে ইনস্টল হয়ে গেলে, এটি FCM APNs ইন্টারফেসের মাধ্যমে বার্তা গ্রহণ করতে পারে। আপনি অবিলম্বে নোটিফিকেশন কম্পোজার বা আপনার অ্যাপ্লিকেশন সার্ভারে তৈরি বার্তাগুলির মাধ্যমে ব্যবহারকারীর বিভাগে বিজ্ঞপ্তি পাঠানো শুরু করতে পারেন৷
সতর্কতা বিজ্ঞপ্তিগুলি পরিচালনা করুন
FCM APN-এর মাধ্যমে Apple অ্যাপকে লক্ষ্য করে সমস্ত বার্তা সরবরাহ করে। UNUserNotificationCenter
ব্যবহার করে APN-এর বিজ্ঞপ্তিগুলি পাওয়ার বিষয়ে আরও জানতে, হ্যান্ডলিং নোটিফিকেশন এবং বিজ্ঞপ্তি-সম্পর্কিত অ্যাকশনগুলিতে অ্যাপলের ডকুমেন্টেশন দেখুন।
আপনাকে অবশ্যই UNUserNotificationCenter ডেলিগেট সেট করতে হবে এবং FCM থেকে ডিসপ্লে নোটিফিকেশন পাওয়ার জন্য উপযুক্ত ডেলিগেট পদ্ধতি প্রয়োগ করতে হবে।
সুইফট
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
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)
}
}
উদ্দেশ্য-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(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert);
}
// 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
প্যারামিটার সেট করুন। APNs পেলোডে আপনি category
কী-এর জন্য যে মানটি ব্যবহার করবেন সেটি ব্যবহার করুন। কাস্টম অ্যাকশনগুলি ব্যবহার করার আগে অবশ্যই নিবন্ধিত হতে হবে৷ আরও তথ্যের জন্য, অ্যাপলের স্থানীয় এবং দূরবর্তী বিজ্ঞপ্তি প্রোগ্রামিং গাইড দেখুন।
আপনার অ্যাপে বার্তা বিতরণের অন্তর্দৃষ্টির জন্য, FCM রিপোর্টিং ড্যাশবোর্ড দেখুন, যা অ্যাপল এবং অ্যান্ড্রয়েড ডিভাইসে পাঠানো এবং খোলা বার্তাগুলির সংখ্যা রেকর্ড করে, সাথে Android অ্যাপগুলির জন্য "ইম্প্রেশন" (ব্যবহারকারীরা দেখেছে বিজ্ঞপ্তিগুলি) ডেটা সহ।
নীরব পুশ বিজ্ঞপ্তিগুলি পরিচালনা করুন
content-available
কী (APN-এর content-available
সমতুল্য) সহ বার্তা পাঠানোর সময়, বার্তাগুলি নীরব বিজ্ঞপ্তি হিসাবে বিতরণ করা হবে, ব্যাকগ্রাউন্ড ডেটা রিফ্রেশের মতো কাজের জন্য আপনার অ্যাপটিকে পটভূমিতে জাগিয়ে তুলবে৷ ফোরগ্রাউন্ড বিজ্ঞপ্তিগুলির বিপরীতে, এই বিজ্ঞপ্তিগুলি অবশ্যই application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
পদ্ধতি ব্যবহার করে পরিচালনা করতে হবে।
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
}
উদ্দেশ্য-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 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);
}
অ্যাপল প্ল্যাটফর্মগুলি ব্যাকগ্রাউন্ড বিজ্ঞপ্তিগুলির বিতরণের গ্যারান্টি দেয় না। ব্যাকগ্রাউন্ড বিজ্ঞপ্তিগুলি ব্যর্থ হতে পারে এমন শর্তগুলি সম্পর্কে জানতে, আপনার অ্যাপে পুশিং ব্যাকগ্রাউন্ড আপডেটে Apple এর ডক্স দেখুন৷
নোটিফিকেশন মেসেজ পেলোড ব্যাখ্যা করুন
বিজ্ঞপ্তি বার্তাগুলির পেলোড হল কী এবং মানগুলির একটি অভিধান৷ APN-এর মাধ্যমে পাঠানো বিজ্ঞপ্তি বার্তাগুলির নিম্নলিখিত APN-এর পেলোড ফর্ম্যাট রয়েছে:
{
"aps" : {
"alert" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
},
"badge" : 1,
},
"customKey" : "customValue"
}
পদ্ধতি সুইজলিং অক্ষম সহ বার্তা পরিচালনা করুন
ডিফল্টরূপে, আপনি যদি UNUserNotificationCenter
এবং Messaging
প্রতিনিধি প্রপার্টিগুলিতে আপনার অ্যাপের অ্যাপ ডেলিগেট ক্লাস বরাদ্দ করেন, তাহলে FCM আপনার অ্যাপ ডেলিগেট ক্লাসকে স্বয়ংক্রিয়ভাবে ডিভাইসের FCM টোকেনের সাথে যুক্ত করতে এবং Analytics বিজ্ঞপ্তি-প্রাপ্ত ইভেন্টগুলিকে পাস করবে। আপনি যদি স্পষ্টভাবে মেথড সুইজলিং অক্ষম করেন, যদি আপনি একটি SwiftUI অ্যাপ তৈরি করেন, অথবা আপনি যদি প্রতিনিধিদের জন্য একটি পৃথক ক্লাস ব্যবহার করেন, তাহলে আপনাকে এই দুটি কাজই ম্যানুয়ালি করতে হবে।
ডিভাইস APNs টোকেনের সাথে FCM টোকেন যুক্ত করতে, apnsToken
প্রপার্টি ব্যবহার করে আপনার অ্যাপ প্রতিনিধির টোকেন রিফ্রেশ হ্যান্ডলারে Messaging
ক্লাসে APN টোকেন পাস করুন।
সুইফট
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken;
}
উদ্দেশ্য-C
- (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)
}
উদ্দেশ্য-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);
}