Bildirim yükünde resim gönderin

FCM HTTP v1 API ve Bildirim oluşturucu bir ekranın yükünde resim bağlantılarının gönderilmesini destekle indirme bildirimi gönderilir. Bu işlev Apple uygulamaları için hem resimleri hem de videoları destekler (dosya boyutu sınırları için Apple dokümanlarına bakın).

Apple uygulamalarında bildirim resimlerini almak ve işleyebilmek için Bildirim Hizmeti Uzantısı Bildirim hizmeti uzantısı, uygulamanızın resmi işlemesini sağlar son kullanıcıya bildirim gösterilmeden önce FCM yüküne teslim edilir.

Bildirim hizmeti uzantısını ayarlayın

Hizmet uzantısı eklemek için şunun için gerekli kurulum görevlerini yerine getirin: bildirimleri değiştirme ve sunma APN'lerde açın ve ardından NotificationService.m için FCM uzantı yardımcı API'sini ekleyin. Özellikle, geri çağırmayı self.contentHandler(self.bestAttemptContent);, aşağıdaki 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şturma

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

  • 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 resim de gönderir. Yaklaşık 10:00'luk bir Kullanıcının cihazında görsel efekt:

Ekran bildirimindeki bir resmin 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);
  });

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

Bkz. HTTP v1 referans belgeleri Şuradaki platforma özgü bloklarda bulunan anahtarlarla ilgili tüm ayrıntıları öğrenin: e-posta mesajı

mutable-content gösterildiği şekilde ayarlandığında bu gönderme isteği, hizmeti etkinleştirir yükte teslim edilen resmi işlemek için alıcı istemcide uzantı oluşturmalıdır.