Skip to content

Send Device Notifications

Redjan Ymeraj edited this page Mar 3, 2017 · 5 revisions
  1. Get the FCM client from the container.

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

        $notification = $fcmClient->createDeviceNotification(
            'Title of Notification', 
            'Body of Notification', 
            'Firebase Token of the device who will recive the notification'
       );
    

    In case you need to send extra data or set other notification properties the Notification Entity supports a set of setters and getters like:

        $notification->setData($array); and $notification->getData();
        $notification->setPriority('high'); // Excepts 2 priorities, high(default) and low
        $notification->setIcon('name of icon located in the native mobile app');
    

    You could also modify the arguments passed in the createDeviceNotification method.

        $notification->setTitle('string');
        $notification->setBody('text');
        $notification->setDeviceToken('string');
    

    The only required field is the Device Token

  3. Send notification

        $fcmClient->sendNotification($notification);
    

Go to Send Topic Notifications

Clone this wiki locally