-
Notifications
You must be signed in to change notification settings - Fork 23
/
example_controller.php
74 lines (63 loc) · 2.3 KB
/
example_controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Users extends CI_Controller
{
/**
* Send to a single device
*/
public function sendNotification()
{
$token = 'Registratin_id'; // push token
$message = "Test notification message";
$this->load->library('fcm');
$this->fcm->setTitle('Test FCM Notification');
$this->fcm->setMessage($message);
/**
* set to true if the notificaton is used to invoke a function
* in the background
*/
$this->fcm->setIsBackground(false);
/**
* payload is userd to send additional data in the notification
* This is purticularly useful for invoking functions in background
* -----------------------------------------------------------------
* set payload as null if no custom data is passing in the notification
*/
$payload = array('notification' => '');
$this->fcm->setPayload($payload);
/**
* Send images in the notification
*/
$this->fcm->setImage('https://firebase.google.com/_static/9f55fd91be/images/firebase/lockup.png');
/**
* Get the compiled notification data as an array
*/
$json = $this->fcm->getPush();
$p = $this->fcm->send($token, $json);
print_r($p);
}
/**
* Send to multiple devices
*/
public function sendToMultiple()
{
$token = array('Registratin_id1', 'Registratin_id2'); // array of push tokens
$message = "Test notification message";
$this->load->library('fcm');
$this->fcm->setTitle('Test FCM Notification');
$this->fcm->setMessage($message);
$this->fcm->setIsBackground(false);
// set payload as null
$payload = array('notification' => '');
$this->fcm->setPayload($payload);
$this->fcm->setImage('https://firebase.google.com/_static/9f55fd91be/images/firebase/lockup.png');
$json = $this->fcm->getPush();
/**
* Send to multiple
*
* @param array $token array of firebase registration ids (push tokens)
* @param array $json return data from getPush() method
*/
$result = $this->fcm->sendMultiple($token, $json);
}
}