Apple के ऐप्लिकेशन में मैसेज पाना

डिवाइस पर क्लाइंट ऐप्लिकेशन इंस्टॉल होने के बाद, उस पर FCM एपीएन इंटरफ़ेस. तुरंत शुरू किया जा सकता है उपयोगकर्ता सेगमेंट को सूचनाएं भेजकर, नोटिफ़िकेशन कंपोज़र या आपके ऐप्लिकेशन सर्वर.

चेतावनी की सूचनाएं मैनेज करना

FCM, एपीएन के ज़रिए Apple के ऐप्लिकेशन को टारगेट करने वाले सभी मैसेज डिलीवर करता है. ज़्यादा जानकारी के लिए के बारे में, UNUserNotificationCenter के ज़रिए एपीएन से मिलने वाली सूचनाएं पाने के बारे में, Apple की पर दस्तावेज़ सूचनाओं और सूचना से जुड़ी कार्रवाइयां मैनेज करना.

आपको UNUserNotificationCenter डेलिगेट और डिसप्ले सूचनाएं पाने के लिए, संपर्कों का ऐक्सेस पाने के सही तरीके लागू करें FCM से कॉपी किया गया.

Swift


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

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(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 पैरामीटर सूचना पेलोड. उस वैल्यू का इस्तेमाल करें जिसे आपको इसके लिए इस्तेमाल करना है: एपीएन पेलोड में category कुंजी है. कस्टम ऐक्शन को इससे पहले रजिस्टर होना चाहिए तो उन्हें इस्तेमाल किया जा सकता है. ज़्यादा जानकारी के लिए, Apple की लोकल और रिमोट नोटिफ़िकेशन प्रोग्रामिंग गाइड.

अपने ऐप्लिकेशन पर मैसेज डिलीवरी की अहम जानकारी के लिए, इसे देखें FCM रिपोर्टिंग डैशबोर्ड, जो Apple और Android डिवाइसों पर, भेजे गए और खोले गए मैसेज की संख्या "इंप्रेशन" का डेटा (उपयोगकर्ताओं की देखी गई सूचनाएं) Android ऐप्लिकेशन के लिए.

साइलेंट पुश नोटिफ़िकेशन मैनेज करना

content-available कुंजी (एपीएन के बराबर) से मैसेज भेजते समय content-available, इन मैसेज को साइलेंट सूचनाओं के तौर पर डिलीवर किया जाएगा, बैकग्राउंड में डेटा रीफ़्रेश करने जैसे कामों के लिए, ऐप्लिकेशन को बैकग्राउंड में चालू करने की सुविधा मिलती है. फ़ोरग्राउंड सूचनाओं के उलट, इन सूचनाओं को application(_:didReceiveRemoteNotification:fetchCompletionHandler:) तरीका.

application(_:didReceiveRemoteNotification:fetchCompletionHandler:) लागू करें जैसा कि दिखाया गया है:

Swift

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
}

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 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 प्लैटफ़ॉर्म, बैकग्राउंड में सूचनाएं भेजने की गारंटी नहीं देते. इसके बारे में जानने के लिए ऐसी स्थितियां जिनकी वजह से बैकग्राउंड में सूचनाएं नहीं भेजी जा सकतीं. इसलिए, Apple के दस्तावेज़ देखें आपके ऐप्लिकेशन पर बैकग्राउंड अपडेट भेजे जा रहे हैं.

सूचना वाले मैसेज पेलोड को समझना

सूचना संदेशों का पेलोड कुंजियां और वैल्यू. एपीएन के ज़रिए भेजे गए सूचना मैसेज, एपीएन के बाद आते हैं पेलोड का फ़ॉर्मैट:

  {
    "aps" : {
      "alert" : {
        "body" : "great match!",
        "title" : "Portugal vs. Denmark",
      },
      "badge" : 1,
    },
    "customKey" : "customValue"
  }

स्विज़लिंग की सुविधा बंद करके मैसेज मैनेज करना

डिफ़ॉल्ट रूप से, अगर आप अपने ऐप्लिकेशन की प्रतिनिधि क्लास को UNUserNotificationCenter और Messaging डेलिगेट प्रॉपर्टी, FCM आपकी डिवाइस के एपीएन टोकन वाला FCM टोकन और पास सूचना पाने की सुविधा इवेंट को Analytics में रिकॉर्ड करना है. अगर आपने मेथड स्विज़लिंग को साफ़ तौर पर बंद किया है, अगर एक SwiftUI ऐप्लिकेशन बनाना है या अगर आपने किसी अन्य व्यक्ति को को ये दोनों काम मैन्युअल तरीके से करने होंगे.

FCM टोकन को डिवाइस एपीएन टोकन से जोड़ने के लिए, एपीएन पास करें आपके ऐप्लिकेशन डेलिगेट में से Messaging क्लास का टोकन टोकन रीफ़्रेश हैंडलर के ज़रिए 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);
}