FCM HTTP v1 API ו- Notifications composer תומכים בשליחת קישורי תמונה במטען של הודעת תצוגה, להורדת תמונה למכשיר לאחר מסירה. פונקציונליות זו תומכת הן בתמונות והן בסרטונים עבור אפליקציות אפל (ראה תיעוד של אפל למגבלות גודל הקבצים).
כדי להיות מסוגל לקבל ולטפל בתמונות התראות באפליקציית Apple, עליך להוסיף תוסף שירות התראות . תוסף שירות ההתראות מאפשר לאפליקציה שלך לטפל בתמונה המועברת במטען ה-FCM לפני הצגת ההודעה למשתמש הקצה.
הגדר את תוסף שירות ההתראות
כדי להוסיף תוסף שירות, בצע את משימות ההגדרה הנדרשות לשינוי והצגת התראות ב-APN, ולאחר מכן הוסף את ממשק ה-API של תוסף FCM ב- NotificationService.m
. באופן ספציפי, במקום להשלים את ההתקשרות חזרה עם 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);
});
מנוחה
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"
}
}
}
}
עיין בתיעוד ההפניה של HTTP v1 לקבלת פרטים מלאים על המפתחות הזמינים בלוקים ספציפיים לפלטפורמה בגוף ההודעה.
עם הגדרת mutable-content
כפי שמוצג, בקשת השליחה הזו מאפשרת לתוסף השירות בלקוח המקבל לטפל בתמונה שנמסרה במטען.