Singleton class responsible for push notifications functionality. More...
#include <juce_PushNotifications.h>
Classes | |
struct | Channel |
Android API level 26 or higher only: Represents notification channel through which notifications will be sent. More... | |
struct | ChannelGroup |
Android API level 26 or higher only: represents a channel group. More... | |
struct | Listener |
Register a listener (ideally on application startup) to receive information about notifications received and any callbacks to async functions called. More... | |
struct | Notification |
Represents a notification that can be sent or received. More... | |
struct | Settings |
Describes settings we want to use for current device. More... | |
Public Member Functions | |
void | addListener (Listener *l) |
bool | areNotificationsEnabled () const |
Checks whether notifications are enabled for given application. More... | |
void | getDeliveredNotifications () const |
Sends a request for a list of notifications delivered. More... | |
String | getDeviceToken () const |
Retrieves current device token. More... | |
void | getPendingLocalNotifications () const |
iOS only: sends an asynchronous request to retrieve a list of notifications that were scheduled and not yet delivered. More... | |
void | removeAllDeliveredNotifications () |
Removes all notifications that were delivered. More... | |
void | removeAllPendingLocalNotifications () |
Unschedules all pending local notifications. More... | |
void | removeDeliveredNotification (const String &identifier) |
Removes a previously delivered notification. More... | |
void | removeListener (Listener *l) |
void | removePendingLocalNotification (const String &identifier) |
Unschedules a pending local notification with a given identifier. More... | |
void | requestPermissionsWithSettings (const Settings &settings) |
Initialises push notifications on current device with the settings provided. More... | |
void | requestSettingsUsed () |
Sends an asynchronous request to retrieve current settings that are currently in use. More... | |
void | sendLocalNotification (const Notification ¬ification) |
On iOS as well as on Android, sends a local notification. More... | |
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. More... | |
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 in the app. More... | |
void | subscribeToTopic (const String &topic) |
Android only: allows to subscribe to messages from a specific topic. More... | |
void | unsubscribeFromTopic (const String &topic) |
Android only: allows to remove a topic subscription that was previously added with subscribeToTopic(). More... | |
Private Member Functions | |
PushNotifications () | |
~PushNotifications () override | |
Static Private Member Functions | |
static void | deleteAll () |
Deletes all extant objects. More... | |
Private Attributes | |
ListenerList< PushNotifications::Listener > | listeners |
Friends | |
bool | juce_handleNotificationIntent (void *) |
struct | JuceFirebaseInstanceIdService |
struct | JuceFirebaseMessagingService |
Singleton class responsible for push notifications functionality.
Both remote and local notifications are supported. To get information about notifications, register a listener on your application startup. It is best to register the listener as soon as possible, because your application can be launched from a push notification too.
To send a local notification create an instance of Notification, fill the necessary fields and call PushNotifications::sendLocalNotification(). When receiving local or remote notifications, inspect the Notification's fields for notification details. Bear in mind that some fields will not be available when receiving a remote notification.
@tags{GUI}
|
private |
|
overrideprivate |
void juce::PushNotifications::addListener | ( | Listener * | l | ) |
bool juce::PushNotifications::areNotificationsEnabled | ( | ) | const |
Checks whether notifications are enabled for given application.
On iOS and OSX this will always return true, use requestSettingsUsed() instead.
|
staticinherited |
Deletes all extant objects.
This shouldn't be used by applications, as it's called automatically in the shutdown code of the JUCEApplicationBase class.
void juce::PushNotifications::getDeliveredNotifications | ( | ) | const |
Sends a request for a list of notifications delivered.
Such notifications are visible in the notification area on the device and they are still waiting for user action/response. When the request is finished Listener::deliveredNotificationsListReceived() will be called.
On iOS, iOS version 10 or higher is required. On Android, API level 18 or higher is required. For unsupported platforms, Listener::deliveredNotificationsListReceived() will return an empty array.
String juce::PushNotifications::getDeviceToken | ( | ) | const |
Retrieves current device token.
Note, it is not a good idea to cache this token because it may change in the meantime. Always call this method to get the current token value.
void juce::PushNotifications::getPendingLocalNotifications | ( | ) | const |
iOS only: sends an asynchronous request to retrieve a list of notifications that were scheduled and not yet delivered.
When the list is retrieved, Listener::pendingLocalNotificationsListReceived() will be called.
void juce::PushNotifications::removeAllDeliveredNotifications | ( | ) |
Removes all notifications that were delivered.
void juce::PushNotifications::removeAllPendingLocalNotifications | ( | ) |
Unschedules all pending local notifications.
iOS only.
void juce::PushNotifications::removeDeliveredNotification | ( | const String & | identifier | ) |
Removes a previously delivered notification.
This can be useful for instance when the information in the notification becomes obsolete.
void juce::PushNotifications::removeListener | ( | Listener * | l | ) |
void juce::PushNotifications::removePendingLocalNotification | ( | const String & | identifier | ) |
Unschedules a pending local notification with a given identifier.
Available from iOS 10.
void juce::PushNotifications::requestPermissionsWithSettings | ( | const Settings & | settings | ) |
Initialises push notifications on current device with the settings provided.
Call this on your application startup and on iOS the first time the application starts, a user will be presented with a permission request dialog to give push notifications permission. Once a user responds, Listener::notificationSettingsReceived() will be called so that you can check what permissions where actually granted. The listener callback will be called on each subsequent startup too (provided you called requestPermissionsWithSettings() on previous application run). This way you can check what are current push notifications permissions.
Note that settings are currently only used on iOS. When calling on other platforms, Settings with no categories and all allow* flags set to true will be received in Listener::notificationSettingsReceived().
You can also call requestSettingsUsed() to explicitly ask for current settings.
void juce::PushNotifications::requestSettingsUsed | ( | ) |
Sends an asynchronous request to retrieve current settings that are currently in use.
These can be exactly the same as used in requestPermissionsWithSettings(), but depending on user's subsequent changes in OS settings, the actual current settings may be different (e.g. user might have later decided to disable sounds).
Note that settings are currently only used on iOS and partially on OSX.
On OSX, only allow* flags are used and they refer to remote notifications only. For local notifications, refer to System Preferences.
When calling this function on other platforms, Settings with no categories and all allow* flags set to true will be received in Listener::notificationSettingsReceived().
void juce::PushNotifications::sendLocalNotification | ( | const Notification & | notification | ) |
On iOS as well as on Android, sends a local notification.
On Android and iOS 10 or above, this will refresh an existing notification if the same identifier is used as in a notification that was already sent and not yet responded by a user.
void juce::PushNotifications::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.
The server must implement XMPP Connection Server protocol (refer to Firebase documentation).
serverSenderId | Represents the sender. Consult your Firebase project settings to retrieve the sender id. |
collapseKey | Remote messages with the same collapse key that were not yet delivered will be collapsed into one, with the newest message replacing all the previous ones. Note that there may be a limit of maximum collapse keys used at the same time and beyond the limit (refer to Firebase documentation) it is not guaranteed which keys will be in use by the server. |
messageId | A unique message ID. Used in error callbacks and debugging. |
messageType | Message type. |
timeToLive | TTL in seconds. If 0, the message sending will be attempted immediately and it will be dropped if the device is not connected. Otherwise, the message will be queued for the period specified. |
additionalData | Collection of key-value pairs to be used as an additional data for the message. |
void juce::PushNotifications::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 in the app.
These have to be setup before notifications can be sent on Android API level 26 or higher.
void juce::PushNotifications::subscribeToTopic | ( | const String & | topic | ) |
Android only: allows to subscribe to messages from a specific topic.
So you could for instance subscribe this device to all "sports" topic messages to receive any remote notifications that have "sports" topic set. Refer to Firebase documentation for how to send topic messages.
void juce::PushNotifications::unsubscribeFromTopic | ( | const String & | topic | ) |
Android only: allows to remove a topic subscription that was previously added with subscribeToTopic().
|
friend |
|
friend |
|
friend |
|
private |