|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Apn\Notifications; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
|
6
|
|
|
use NotificationChannels\Apn\ApnChannel; |
|
7
|
|
|
use NotificationChannels\Apn\ApnMessage; |
|
8
|
|
|
use Illuminate\Notifications\Notification; |
|
9
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
10
|
|
|
|
|
11
|
|
|
class ApnTestNotification extends Notification |
|
12
|
|
|
{ |
|
13
|
|
|
use Queueable; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The body of the test notification that will |
|
17
|
|
|
* be sent. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
private $notificationBody; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The title of the test notification that will |
|
25
|
|
|
* be sent. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $notificationTitle; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The badge number that will be sent with the |
|
33
|
|
|
* notification. |
|
34
|
|
|
* |
|
35
|
|
|
* @var integer |
|
36
|
|
|
*/ |
|
37
|
|
|
private $badgeNumber; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The sound that will be played when the device |
|
41
|
|
|
* receives the notification. |
|
42
|
|
|
* |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
private $sound; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* NewChatMessage constructor. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $notificationTitle |
|
51
|
|
|
* @param string $notificationBody |
|
52
|
|
|
* @param int $badgeNumber |
|
53
|
|
|
* @param string $sound |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct( |
|
56
|
|
|
string $notificationTitle, |
|
57
|
|
|
string $notificationBody, |
|
58
|
|
|
int $badgeNumber, |
|
59
|
|
|
string $sound = 'default' |
|
60
|
|
|
) { |
|
61
|
|
|
$this->notificationBody = $notificationBody; |
|
62
|
|
|
$this->notificationTitle = $notificationTitle; |
|
63
|
|
|
$this->badgeNumber = $badgeNumber; |
|
64
|
|
|
$this->sound = $sound; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Set the notification route as 'ApnChannel'. |
|
69
|
|
|
* |
|
70
|
|
|
* @param mixed $notifiable |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
public function via($notifiable): array |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
return [ApnChannel::class]; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Use the APN service to send a push notification |
|
80
|
|
|
* to any iOS devices. |
|
81
|
|
|
* |
|
82
|
|
|
* @param $notifiable |
|
83
|
|
|
* @return ApnMessage |
|
84
|
|
|
*/ |
|
85
|
|
|
public function toApn($notifiable): ApnMessage |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
return ApnMessage::create() |
|
88
|
|
|
->badge($this->badgeNumber) |
|
89
|
|
|
->title($this->notificationTitle) |
|
90
|
|
|
->body($this->notificationBody) |
|
91
|
|
|
->sound($this->sound); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.