Skip to content

Send Device Notifications

Redjan Ymeraj edited this page Dec 2, 2016 · 5 revisions
  1. Get the FCM client from the container.

      $fcmClient = $this->getContainer()->get('redjan_ym_fcm.client');
  2. Create a Notification. For now FCMBundle supports only Device Notifications. Topic Notifications will be added in the future versions.

        $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.

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

    The only required field is the Device Token

  3. Send notification

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