सूचना पेलोड में इमेज भेजें

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

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

सूचना सेवा एक्सटेंशन सेट अप करना

सर्विस एक्सटेंशन जोड़ने के लिए, सेटअप से जुड़े ज़रूरी काम करें सूचनाओं में बदलाव करना और उन्हें प्रज़ेंट करना एपीएन में, और उसके बाद NotificationService.m में FCM एक्सटेंशन हेल्पर एपीआई जोड़ें. खास तौर पर, कॉलबैक को पूरा करने के बजाय self.contentHandler(self.bestAttemptContent);, इसे FIRMessaging extensionHelper की मदद से पूरा करें, जैसा कि यहां दिखाया गया है:

@interface NotificationService () <NSURLSessionDelegate>
@property(nonatomic) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property(nonatomic) UNMutableNotificationContent *bestAttemptContent;
@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];

    // Modify the notification content here as you wish
    self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]",
    self.bestAttemptContent.title];

  // Call FIRMessaging extension helper API.
  [[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent
                                            withContentHandler:contentHandler];

}
...

मैसेज भेजने का अनुरोध करें

सूचना भेजने के अपने अनुरोध में, ये ApnsConfig सेट करें विकल्प:

  • fcm_options.image में इमेज का यूआरएल है
  • headers({ "mutable-content": 1})

भेजने के अनुरोध के इस उदाहरण में, सभी प्लैटफ़ॉर्म पर सूचना का एक ही टाइटल भेजा गया है. हालांकि, इससे एक इमेज भी भेजी जाती है. यहाँ इसका एक अनुमान दिया गया है: उपयोगकर्ता के डिवाइस पर विज़ुअल इफ़ेक्ट:

डिसप्ले सूचना में इमेज की आसान ड्रॉइंग

Node.js

const topicName = 'industry-tech';

const message = {
  notification: {
    title: 'Sparky says hello!'
  },
  android: {
    notification: {
      imageUrl: 'https://foo.bar.pizza-monster.png'
    }
  },
  apns: {
    payload: {
      aps: {
        'mutable-content': 1
      }
    },
    fcm_options: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  webpush: {
    headers: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  topic: topicName,
};

getMessaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

REST

POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
  "message":{
     "topic":"industry-tech",
     "notification":{
       "title":"Sparky says hello!",
     },
     "android":{
       "notification":{
         "image":"https://foo.bar/pizza-monster.png"
       }
     },
     "apns":{
       "payload":{
         "aps":{
           "mutable-content":1
         }
       },
       "fcm_options": {
           "image":"https://foo.bar/pizza-monster.png"
       }
     },
     "webpush":{
       "headers":{
         "image":"https://foo.bar/pizza-monster.png"
       }
     }
   }
 }

ज़्यादा जानकारी के लिए, एचटीटीपी v1 के रेफ़रंस के लिए दस्तावेज़ में प्लैटफ़ॉर्म-विशिष्ट ब्लॉक में उपलब्ध कुंजियों के बारे में पूरी जानकारी के लिए ईमेल का मुख्य हिस्सा.

अगर mutable-content को दिखाया गया है, तो मैसेज भेजने का यह अनुरोध इस सेवा को चालू कर देता है पेलोड में डिलीवर की गई इमेज को हैंडल करने के लिए, पाने वाले क्लाइंट पर एक एक्सटेंशन का इस्तेमाल करें.