একটি Apple অ্যাপে বার্তা পান

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

উদ্দেশ্য গ

// 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 কী-এর জন্য যে মান ব্যবহার করবেন তা ব্যবহার করুন। কাস্টম অ্যাকশনগুলি ব্যবহার করার আগে অবশ্যই নিবন্ধিত হতে হবে৷ আরও তথ্যের জন্য, অ্যাপলের স্থানীয় এবং দূরবর্তী বিজ্ঞপ্তি প্রোগ্রামিং গাইড দেখুন।

আপনার অ্যাপে বার্তা বিতরণের অন্তর্দৃষ্টির জন্য, এফসিএম রিপোর্টিং ড্যাশবোর্ড দেখুন, যা অ্যাপল এবং অ্যান্ড্রয়েড ডিভাইসে পাঠানো এবং খোলা বার্তাগুলির সংখ্যা রেকর্ড করে, সাথে 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
}

উদ্দেশ্য গ

- (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 আপনার অ্যাপ ডেলিগেট শ্রেণীকে স্বয়ংক্রিয়ভাবে ডিভাইসের APN টোকেনের সাথে সংযুক্ত করতে এবং অ্যানালিটিক্সে বিজ্ঞপ্তি-প্রাপ্ত ইভেন্টগুলিকে পাস করার জন্য স্যুইজল করবে। আপনি যদি স্পষ্টভাবে মেথড সুইজলিং অক্ষম করেন, যদি আপনি একটি SwiftUI অ্যাপ তৈরি করেন, অথবা আপনি যদি প্রতিনিধিদের জন্য একটি পৃথক ক্লাস ব্যবহার করেন, তাহলে আপনাকে এই দুটি কাজই ম্যানুয়ালি করতে হবে।

ডিভাইস APNs টোকেনের সাথে 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;
}

অ্যানালিটিক্সে বিজ্ঞপ্তি প্রাপ্তির তথ্য পাস করতে, 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);
}