JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_PushNotifications.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
30#if ! JUCE_ANDROID && ! JUCE_IOS && ! JUCE_MAC
31bool PushNotifications::Notification::isValid() const noexcept { return true; }
32#endif
33
34PushNotifications::Notification::Notification (const Notification& other)
35 : identifier (other.identifier),
36 title (other.title),
37 body (other.body),
38 subtitle (other.subtitle),
39 groupId (other.groupId),
40 badgeNumber (other.badgeNumber),
41 soundToPlay (other.soundToPlay),
42 properties (other.properties),
43 category (other.category),
44 triggerIntervalSec (other.triggerIntervalSec),
45 repeat (other.repeat),
46 icon (other.icon),
47 channelId (other.channelId),
48 largeIcon (other.largeIcon),
49 tickerText (other.tickerText),
50 actions (other.actions),
51 progress (other.progress),
52 person (other.person),
53 type (other.type),
54 priority (other.priority),
55 lockScreenAppearance (other.lockScreenAppearance),
56 publicVersion (other.publicVersion.get() != nullptr ? new Notification (*other.publicVersion) : nullptr),
57 groupSortKey (other.groupSortKey),
58 groupSummary (other.groupSummary),
59 accentColour (other.accentColour),
60 ledColour (other.ledColour),
61 ledBlinkPattern (other.ledBlinkPattern),
62 vibrationPattern (other.vibrationPattern),
63 shouldAutoCancel (other.shouldAutoCancel),
64 localOnly (other.localOnly),
65 ongoing (other.ongoing),
66 alertOnlyOnce (other.alertOnlyOnce),
67 timestampVisibility (other.timestampVisibility),
68 badgeIconType (other.badgeIconType),
69 groupAlertBehaviour (other.groupAlertBehaviour),
70 timeoutAfterMs (other.timeoutAfterMs)
71{
72}
73
74//==============================================================================
76
77PushNotifications::PushNotifications()
78 #if JUCE_PUSH_NOTIFICATIONS
79 : pimpl (new Pimpl (*this))
80 #endif
81{
82}
83
84PushNotifications::~PushNotifications() { clearSingletonInstance(); }
85
86void PushNotifications::addListener (Listener* l) { listeners.add (l); }
87void PushNotifications::removeListener (Listener* l) { listeners.remove (l); }
88
90{
91 #if JUCE_PUSH_NOTIFICATIONS && (JUCE_IOS || JUCE_MAC)
92 pimpl->requestPermissionsWithSettings (settings);
93 #else
94 listeners.call ([] (Listener& l) { l.notificationSettingsReceived ({}); });
95 #endif
96}
97
99{
100 #if JUCE_PUSH_NOTIFICATIONS && (JUCE_IOS || JUCE_MAC)
101 pimpl->requestSettingsUsed();
102 #else
103 listeners.call ([] (Listener& l) { l.notificationSettingsReceived ({}); });
104 #endif
105}
106
108{
109 #if JUCE_PUSH_NOTIFICATIONS
110 return pimpl->areNotificationsEnabled();
111 #else
112 return false;
113 #endif
114}
115
117{
118 #if JUCE_PUSH_NOTIFICATIONS
119 pimpl->getDeliveredNotifications();
120 #endif
121}
122
124{
125 #if JUCE_PUSH_NOTIFICATIONS
126 pimpl->removeAllDeliveredNotifications();
127 #endif
128}
129
131{
132 #if JUCE_PUSH_NOTIFICATIONS
133 return pimpl->getDeviceToken();
134 #else
135 return {};
136 #endif
137}
138
140{
141 #if JUCE_PUSH_NOTIFICATIONS
142 pimpl->setupChannels (groups, channels);
143 #endif
144}
145
147{
148 #if JUCE_PUSH_NOTIFICATIONS
149 pimpl->getPendingLocalNotifications();
150 #endif
151}
152
154{
155 #if JUCE_PUSH_NOTIFICATIONS
156 pimpl->removeAllPendingLocalNotifications();
157 #endif
158}
159
161{
162 #if JUCE_PUSH_NOTIFICATIONS
163 pimpl->subscribeToTopic (topic);
164 #endif
165}
166
168{
169 #if JUCE_PUSH_NOTIFICATIONS
170 pimpl->unsubscribeFromTopic (topic);
171 #endif
172}
173
174
176{
177 #if JUCE_PUSH_NOTIFICATIONS
178 pimpl->sendLocalNotification (n);
179 #endif
180}
181
183{
184 #if JUCE_PUSH_NOTIFICATIONS
185 pimpl->removeDeliveredNotification (identifier);
186 #endif
187}
188
190{
191 #if JUCE_PUSH_NOTIFICATIONS
192 pimpl->removePendingLocalNotification (identifier);
193 #endif
194}
195
198 [[maybe_unused]] const String& messageId,
200 [[maybe_unused]] int timeToLive,
202{
203 #if JUCE_PUSH_NOTIFICATIONS
204 pimpl->sendUpstreamMessage (serverSenderId,
206 messageId,
210 #endif
211}
212
213//==============================================================================
229
230} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
Singleton class responsible for push notifications functionality.
void setupChannels(const Array< ChannelGroup > &groups, const Array< Channel > &channels)
Android API level 26 or higher only: configures notification channel groups and channels to be used i...
void removePendingLocalNotification(const String &identifier)
Unschedules a pending local notification with a given identifier.
void getPendingLocalNotifications() const
iOS only: sends an asynchronous request to retrieve a list of notifications that were scheduled and n...
void removeAllPendingLocalNotifications()
Unschedules all pending local notifications.
void subscribeToTopic(const String &topic)
Android only: allows to subscribe to messages from a specific topic.
void getDeliveredNotifications() const
Sends a request for a list of notifications delivered.
void removeAllDeliveredNotifications()
Removes all notifications that were delivered.
void removeDeliveredNotification(const String &identifier)
Removes a previously delivered notification.
bool areNotificationsEnabled() const
Checks whether notifications are enabled for given application.
void sendUpstreamMessage(const String &serverSenderId, const String &collapseKey, const String &messageId, const String &messageType, int timeToLive, const StringPairArray &additionalData)
Android only: sends an upstream message to your app server.
void sendLocalNotification(const Notification &notification)
On iOS as well as on Android, sends a local notification.
void unsubscribeFromTopic(const String &topic)
Android only: allows to remove a topic subscription that was previously added with subscribeToTopic()...
void requestSettingsUsed()
Sends an asynchronous request to retrieve current settings that are currently in use.
void requestPermissionsWithSettings(const Settings &settings)
Initialises push notifications on current device with the settings provided.
String getDeviceToken() const
Retrieves current device token.
Describes settings we want to use for current device.
A container for holding a set of strings which are keyed by another string.
The JUCE String class!
Definition juce_String.h:53
#define JUCE_IMPLEMENT_SINGLETON(Classname)
This is a counterpart to the JUCE_DECLARE_SINGLETON macros.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
Register a listener (ideally on application startup) to receive information about notifications recei...
virtual void notificationSettingsReceived(const Settings &settings)
This callback will be called after you call requestSettingsUsed() or requestPermissionsWithSettings()...
virtual void handleNotification(bool isLocalNotification, const Notification &notification)
This can be called in multiple different situations, depending on the OS and the situation.
virtual void upstreamMessageSendingError(const String &messageId, const String &error)
Called when there was an error sending an upstream message with PushNotifications::sendUpstreamMessag...
virtual void deviceTokenRefreshed(const String &token)
Called whenever a token gets refreshed.
virtual void upstreamMessageSent(const String &messageId)
Called when an upstream message sent with PushNotifications::sendUpstreamMessage() has been sent succ...
virtual void remoteNotificationsDeleted()
Called when Firebase Cloud Messaging server deletes pending messages.
virtual void handleNotificationAction(bool isLocalNotification, const Notification &notification, const String &actionIdentifier, const String &optionalResponse)
This can be called when a user performs some action on the notification such as pressing on an action...
virtual void localNotificationDismissedByUser(const Notification &notification)
For iOS10 and Android, this can be also called when a user dismissed the notification before respondi...
virtual void deliveredNotificationsListReceived(const Array< Notification > &notifications)
Called after getDeliveredNotifications() request is fulfilled.
virtual void pendingLocalNotificationsListReceived(const Array< Notification > &notifications)
Called when the list of pending notifications, requested by calling getPendingLocalNotifications() is...
Represents a notification that can be sent or received.
bool isValid() const noexcept
Checks whether a given notification is correctly configured for a given OS.