Skip to content

Send Device Notifications

Redjan Ymeraj edited this page Jan 27, 2025 · 6 revisions
  1. Get the FCM client from the container.

      $fcmClient = $this->getContainer()->get('redjan_ym_fcm.client');
  2. Create a Device Notification.

        use RedjanYm\FCM\Notification;
        use RedjanYm\FCM\Recipient\Device;
    
        $testToken = 'this-is-a-token';
    
        $recipient = new Device($testToken);
        $notification = new Notification($recipient, 'Title', 'Body', ['key' => 'value']);
    
        $fcmClient->send($notification);
    

    In case you need to set other notification properties the Notification class supports many public properties like:

        $notification->priority = 'high'; // Excepts 2 priorities, high(default) and low
        $notification->icon = 'name of icon located in the native mobile app';
    
        // And many more
    
  3. Send notification

        $fcmClient->sendNotification($notification);
    
Clone this wiki locally