FCM HTTP v1 API और Notifications Creator की मदद से, डिसप्ले सूचना के पेलोड में इमेज के लिंक भेजे जा सकते हैं. इससे डिलीवरी के बाद, डिवाइस में इमेज डाउनलोड की जा सकती है. यह सुविधा 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
को दिखाए गए रूप में सेट किया जाता है, तो भेजने का यह अनुरोध पाने वाले क्लाइंट पर सर्विस एक्सटेंशन को चालू कर देता है, ताकि वह पेलोड में डिलीवर की गई इमेज को मैनेज कर सके.