Home > Enterprise >  How can I send multiple notifications that should be visible to all user which was login in to the w
How can I send multiple notifications that should be visible to all user which was login in to the w

Time:06-27

How can I send multiple notifications that should be visible to all user which was login in to the web browser using firebase in CodeIgniter? all action-related notifications should be visible to all users which were login into the same branch on the web browser? how can I do this to help with this question?

here is my code

public function push_notification($branches,$sec, $msg, $title, $type, $notification_id, $table_name, $employe = null)
{


    $devices          = $this->getEmployeeWithdevissse($branches,$sec, $employe);
    $registration_ids = array();
    if ($devices) {
        foreach ($devices as $key => $device) {
            if ($device->device_token) {
                $registration_ids[] = $device->device_token;
            }
        }
    }

    if ($registration_ids) {
        $data = array(
            'title'           => $title,
            'message'         => $msg,
            'table_name'      => $notification_id,
            'type'            => $type,
            'notification_id' => $table_name,
        );

        $notification = array(
            'title'           => $title,
            'body'            => $msg,
            'table_name'      => $notification_id,
            'type'            => $type,
            'icon'            => 'myicon',
            'sound'           => 'default',
            'notification_id' => $table_name,
        );
        //FCM api URL
        $url                        = 'https://fcm.googleapis.com/fcm/send';
        $fields                     = array();
        $fields['notification']     = $notification;
        $fields['data']             = $data;
        $fields['registration_ids'] = $registration_ids;
        $fields['priority']         = "high";
        $headers                    = array(
            'Content-Type:application/json',
            'Authorization:key=' . $this->server_key,
        );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
        $result = curl_exec($ch);
        if ($result === false) {
            die('FCM Send Error: ' . curl_error($ch));
        }
        curl_close($ch);
        return $result;
    } else {
        return false;
    }
}

CodePudding user response:

It's not possible, with firebase you can make custom.

  • Related