Bildirim yükünde bir resim gönder

FCM HTTP v1 API'si ve Notifications oluşturucu , teslimattan sonra cihaza resim indirmek için bir ekran bildiriminin yükünde resim bağlantıları göndermeyi destekler. Bu işlevsellik, Apple uygulamaları için hem görüntüleri hem de videoları destekler (dosya boyutu sınırları için Apple belgelerine bakın).

Bir Apple uygulamasında bildirim resimlerini alıp işleyebilmek için bir Bildirim Hizmeti Uzantısı eklemelisiniz. Bildirim hizmeti uzantısı, uygulamanızın, bildirimi son kullanıcıya göstermeden önce FCM yükünde teslim edilen görüntüyü işlemesine olanak tanır.

Bildirim hizmeti uzantısını ayarlayın

Bir hizmet uzantısı eklemek için, APN'lerde bildirimleri değiştirmek ve sunmak için gerekli kurulum görevlerini gerçekleştirin ve ardından NotificationService.m FCM uzantısı yardımcı API'sini ekleyin. Özellikle, geri aramayı self.contentHandler(self.bestAttemptContent); , gösterildiği gibi FIRMessaging extensionHelper ile tamamlayın:

@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];

}
...

Gönderme isteğini oluşturun

Bildirim gönderme isteğinizde aşağıdaki ApnsConfig seçeneklerini ayarlayın:

  • resim URL'sini içeren fcm_options.image
  • headers({ "mutable-content": 1})

Aşağıdaki örnek gönderme isteği, tüm platformlara ortak bir bildirim başlığı gönderir, ancak aynı zamanda bir görüntü de gönderir. Aşağıda, bir kullanıcının cihazındaki görsel efektin bir tahmini verilmiştir:

Bir görüntü bildiriminde bir görüntünün basit çizimi

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

DİNLENMEK

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

İleti gövdesindeki platforma özgü bloklarda bulunan anahtarlarla ilgili tüm ayrıntılar için HTTP v1 referans belgelerine bakın.

mutable-content gösterildiği gibi ayarlandığında, bu gönderme isteği, alıcı istemcideki hizmet uzantısının yükte teslim edilen görüntüyü işlemesini sağlar.