Account created on 5 April 2018, over 6 years ago
#

Recent comments

Should like this:

 /** @var FirebaseMessageService $messageService */
 $messageService = \Drupal::service('firebase.message');
 $messageService->setRecipients($fcmToken);
 // Notification
 $notification = new Notification('Title goes here');
 $notification->setBody('Body goes here');
 // Message data
 $messageData = MessageData::fromArray([
  'score' => '3x1',
  'date' => '2017-10-10',
  'optional' => 'Data is used to send silent pushes. Otherwise, optional.',
]);
 // Message
 $message = new Message($notification);
 $message->setData($messageData);
 $messageService->setMessage($message);
 // Android config
 $android_config = new AndroidConfig();
 $android_config->setPriority('high');
 $message->setAndroidConfig($android_config);
 // Apple config
 $apns_config = new ApnsConfig();
 $apns_config->setHeaders(['apns-priority' => '5']);
 $apns_config->setPayload([
      'aps'=> [
        'mutable-content' => 1,
        'content-available' => 1
      ]
    ]);
$message->setApnsConfig($apns_config);

$result = $messageService->sendToTokens();
Production build 0.71.5 2024