Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

716 lines
39KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. namespace juce
  20. {
  21. /** Singleton class responsible for push notifications functionality. Both remote and
  22. local notifications are supported. To get information about notifications,
  23. register a listener on your application startup. It is best to register the
  24. listener as soon as possible, because your application can be launched from
  25. a push notification too.
  26. To send a local notification create an instance of Notification, fill the necessary
  27. fields and call PushNotifications::sendLocalNotification(). When receiving local or
  28. remote notifications, inspect the Notification's fields for notification details.
  29. Bear in mind that some fields will not be available when receiving a remote
  30. notification.
  31. @tags{GUI}
  32. */
  33. class JUCE_API PushNotifications : private DeletedAtShutdown
  34. {
  35. public:
  36. #ifndef DOXYGEN
  37. JUCE_DECLARE_SINGLETON (PushNotifications, false)
  38. #endif
  39. //==============================================================================
  40. /** Represents a notification that can be sent or received. */
  41. struct Notification
  42. {
  43. Notification() = default;
  44. Notification (const Notification& other);
  45. /** Checks whether a given notification is correctly configured for a given OS. */
  46. bool isValid() const noexcept;
  47. /** Represents an action on a notification that can be presented as a button or a text input.
  48. On Android, each notification has its action specified explicitly, on iOS you configure an
  49. allowed set of actions on startup and pack them into categories (see Settings).
  50. */
  51. struct Action
  52. {
  53. /** Controls the appearance of this action. */
  54. enum Style
  55. {
  56. button, /**< Show this action as a button. */
  57. text /**< Show this action as a text input field (on Android API 20 or higher is required). */
  58. };
  59. /** @name Common fields */
  60. /**@{*/
  61. Style style = button;
  62. String title; /**< Required. the name of the action displayed to the user. */
  63. String textInputPlaceholder; /**< Optional: placeholder text for text input notification.
  64. Note that it will be ignored if button style is used. */
  65. var parameters; /**< Optional: additional parameters that can be passed. */
  66. /**@}*/
  67. /** @name iOS only fields */
  68. /**@{*/
  69. String identifier; /**< Required: unique identifier. This should be one of the
  70. identifiers set with requestPermissionsWithSettings(). */
  71. bool triggerInBackground = false; /**< Whether the app can process the action in background. */
  72. bool destructive = false; /**< Whether to display the action as destructive. */
  73. String textInputButtonText; /**< Optional: Text displayed on text input notification
  74. button (from iOS 10 only).
  75. Note that it will be ignored if style is set to Style::button. */
  76. /**@}*/
  77. /** @name Android only fields */
  78. /**@{*/
  79. String icon; /**< Optional: name of an icon file (without an extension) to be used for
  80. this action. This must be the name of one of the image
  81. files included into resources when exporting an Android project
  82. (see "Extra Android Raw Resources" setting in Projucer).
  83. Note that not all Android versions support an icon for an action, though
  84. it is recommended to provide it nevertheless. */
  85. StringArray allowedResponses; /**< Optional: a list of possible answers if the answer set is limited.
  86. When left empty, then the user will be able to input any text. */
  87. /**@}*/
  88. };
  89. //==============================================================================
  90. /** @name Common fields */
  91. /**@{*/
  92. String identifier; /**< Required: unique id that can be used to later dismiss the notification
  93. (on iOS available from version 10). */
  94. String title; /**< Required: the title of the notification, usually displayed in the first row. */
  95. String body; /**< Required: the content of the notification, usually displayed in the second row. */
  96. String subtitle; /**< Optional: additional text, that may be displayed e.g. in the third row or in the header
  97. area. Note that on Android, depending on OS version, this may fight for
  98. space with other components of the notification, so use this field
  99. judiciously. On iOS available from version 10. On Android available from API 16. */
  100. String groupId; /**< Optional: allows the OS to visually group, collapse, and expand a set of notifications,
  101. note that OS may automatically group notifications if no groupId is specified.
  102. Available on Android API 20 or above and iOS 10 or above. */
  103. int badgeNumber = 0; /**< Optional: on platforms that support it, can set a number this notification represents. */
  104. URL soundToPlay; /**< Optional: empty when the notification should be silent. When the name is set to
  105. "default_os_sound", then a default sound will be used.
  106. For a custom sound on OSX, set the URL to the name of a sound file (preferably without
  107. an extension) and place the sound file directly in bundle's "Resources" directory (you
  108. can use "Xcode Resource" tickbox in Projucer to achieve that), i.e. it cannot be in a
  109. subdirectory of "Resources" like "Resources/sound". Alternatively, if a sound file
  110. cannot be found in bundle's "Resources" directory, the OS may look for the sound in the
  111. following paths: "~/Library/Sounds", "/Library/Sounds", "/Network/Library/Sounds",
  112. "/System/Library/Sounds".
  113. For a custom sound on iOS, set the URL to a relative path within your bundle, including
  114. file extension. For instance, if your bundle contains "sounds" folder with "my_sound.caf"
  115. file, then the URL should be "sounds/my_sound.caf".
  116. For a custom sound on Android, set URL to the name of a raw resource file
  117. (without an extension) that was included when exporting an Android project in
  118. Projucer (see "Extra Android Raw Resources" setting). */
  119. var properties; /**< Optional: collection of additional properties that may be passed as a dictionary. */
  120. /**@}*/
  121. //==============================================================================
  122. /** @name iOS only fields */
  123. /**@{*/
  124. String category; /**< Required: determines set of actions that will appear (as per setup done
  125. in requestPermissionsWithSettings()). */
  126. double triggerIntervalSec = 0.; /**< Optional: specifies number of seconds before the notification should trigger. */
  127. bool repeat = false; /**< Optional: allows the notification to continuously retrigger after
  128. triggerIntervalSec seconds. Available from iOS 10. */
  129. /**@}*/
  130. //==============================================================================
  131. /** @name Android only fields */
  132. /**@{*/
  133. String icon; /**< Required: name of an icon file (without an extension) to be used for
  134. this notification. This must be the name of one of the image
  135. files included into resources when exporting an Android project
  136. (see "Extra Android Raw Resources" setting in Projucer). */
  137. String channelId; /**< Required for Android API level 26 or above: specifies notification channel id. Refer to
  138. setupChannels(). Ignored on earlier Android versions. */
  139. Image largeIcon; /**< Optional: an additional large icon displayed in the notification content view. */
  140. String tickerText; /**< Optional: ticker text used for accessibility services. */
  141. Array<Action> actions; /**< Optional: actions associated with the notification. Note that the OS may allow only a limited
  142. number of actions to be presented, so always present most important actions first.
  143. Available from Android API 16 or above. */
  144. /** Used to represent a progress of some operation. */
  145. struct Progress
  146. {
  147. int max = 0; /**< Max possible value of a progress. A typical usecase is to set max to 100 and increment
  148. current's value as percentage complete. */
  149. int current = 0; /**< Current progress value, should be from 0 to max. */
  150. bool indeterminate = false; /**< If true, then the progress represents a continuing activity indicator with ongoing
  151. animation and no numeric value. */
  152. };
  153. Progress progress; /**< Optional: set to default (0, 0, false), to disable progress display. */
  154. /** Metadata that can be used by the OS to better handle the notification, depending on its priority. */
  155. enum Type
  156. {
  157. unspecified, /**< Category not set. */
  158. alarm, /**< Alarm or timer. */
  159. call, /**< Incoming voice/video call or similar. */
  160. email, /**< Async message like email. */
  161. error, /**< Error in background operation or authentication status. */
  162. event, /**< Calendar event. */
  163. message, /**< Incoming message (sms, instant message etc.). */
  164. taskProgress, /**< Progress for a long-running background operation. */
  165. promo, /**< Promotion or advertisement. */
  166. recommendation, /**< Specific, single thing related recommendation. */
  167. reminder, /**< User-scheduled reminder. */
  168. service, /**< Running background service. */
  169. social, /**< Social network or sharing update. */
  170. status, /**< Ongoing information about device or contextual status. */
  171. system, /**< System or device status update. */
  172. transport /**< Media transport control for playback. */
  173. };
  174. /** Metadata used as a hint to the OS about the priority of the notification. */
  175. enum Priority
  176. {
  177. veryLow = -2,
  178. low = -1,
  179. medium = 0,
  180. high = 1,
  181. veryHigh = 2
  182. };
  183. String person; /**< Optional: additional metadata used as a hint to OS that a notification is
  184. related to a specific person. Can be useful for instance messaging apps.
  185. Available from Android API 21 or above. */
  186. Type type = unspecified; /**< Optional. Available from Android API 21 or above. */
  187. Priority priority = medium; /**< Optional. Available from Android API 16 or above. */
  188. /** Describes how to show the notification when the screen is locked. Available from Android API 21 or above. */
  189. enum LockScreenAppearance
  190. {
  191. dontShow = -1, /**< The notification is not allowed on the lock screen */
  192. showPartially = 0, /**< Only some information is allowed on the lock screen */
  193. showCompletely = 1 /**< The entire notification is allowed on the lock screen */
  194. };
  195. LockScreenAppearance lockScreenAppearance = showPartially; /**< Optional. */
  196. std::unique_ptr<Notification> publicVersion; /**< Optional: if you set lockScreenAppearance to showPartially,
  197. then you can provide "public version" of your notification
  198. that will be displayed on the lock screen. This way you can
  199. control what information is visible when the screen is locked. */
  200. String groupSortKey; /**< Optional: Used to order notifications within the same group. Available from Android API 20 or above. */
  201. bool groupSummary = false; /**< Optional: if true, then this notification will be a group summary of the group set with groupId.
  202. Available from Android API 20 or above. */
  203. Colour accentColour; /**< Optional: sets accent colour. The default colour will be used if accentColour is not set.
  204. Available from Android API 21 or above. */
  205. Colour ledColour; /**< Optional: Sets the led colour. The hardware will do its best to approximate the colour.
  206. The default colour will be used if ledColour is not set. */
  207. /** Allows to control the time the device's led is on and off. */
  208. struct LedBlinkPattern
  209. {
  210. int msToBeOn = 0; /**< The led will be on for the given number of milliseconds, after which it will turn off. */
  211. int msToBeOff = 0; /**< The led will be off for the given number of milliseconds, after which it will turn on. */
  212. };
  213. LedBlinkPattern ledBlinkPattern; /**< Optional. */
  214. Array<int> vibrationPattern; /**< Optional: sets the vibration pattern in milliseconds. The first value indicates how long
  215. to wait until vibration starts. The second value indicates how long to vibrate. The third
  216. value will say how long to not vibrate and so on. For instance, if the pattern is:
  217. 1000, 2000, 3000, 4000 - then one second after receiving a notification the device will
  218. vibrate for two seconds, followed by 3 seconds of no vibration and finally, 4 seconds of
  219. vibration. */
  220. bool shouldAutoCancel = true; /**< Optional: If true, the notification will be automatically cancelled when a user clicks it in the panel. */
  221. bool localOnly = true; /**< Optional: whether or not the notification should bridge to other devices.
  222. Available from Android API 20 or above. */
  223. bool ongoing = false; /**< Optional: If true, then it cannot be dismissed by the user and it must be dismissed manually.
  224. Typically used for ongoing background tasks that the user is actively engaged with. To
  225. dismiss such notification, you need to call removeDeliveredNotification() or
  226. removeAllDeliveredNotifications(). */
  227. bool alertOnlyOnce = false; /**< Optional: Set this flag if you would only like the sound, vibrate and ticker to be played if the notification
  228. is not already showing. */
  229. /** Controls timestamp visibility and format. */
  230. enum TimestampVisibility
  231. {
  232. off, /**< Do not show timestamp. */
  233. normal, /**< Show normal timestamp. */
  234. chronometer, /**< Show chronometer as a stopwatch. Available from Android API 16 or above. */
  235. countDownChronometer /**< Set the chronometer to count down instead of counting up. Available from Android API 24 or above.*/
  236. };
  237. TimestampVisibility timestampVisibility = normal; /**< Optional. */
  238. /** Controls badge icon type to use if a notification is shown as a badge. Available from Android API 26 or above. */
  239. enum BadgeIconType
  240. {
  241. none,
  242. small,
  243. large
  244. };
  245. BadgeIconType badgeIconType = large;
  246. /** Controls sound and vibration behaviour for group notifications. Available from Android API 26 or above. */
  247. enum GroupAlertBehaviour
  248. {
  249. alertAll, /**< both child notifications and group notifications should produce sound and vibration. */
  250. AlertSummary, /**< all child notifications in the group should have no sound nor vibration, even
  251. if corresponding notification channel has sounds and vibrations enabled. */
  252. AlertChildren /**< summary notifications in the group should have no sound nor vibration, even if
  253. corresponding notification channel has sounds and vibrations enabled. */
  254. };
  255. GroupAlertBehaviour groupAlertBehaviour = alertAll;
  256. int timeoutAfterMs = 0; /**< specifies a duration in milliseconds, after which the notification should be
  257. cancelled, if it is not already canceled. Available from Android API 26 or above. */
  258. /**@}*/
  259. };
  260. //==============================================================================
  261. /** Describes settings we want to use for current device. Note that at the
  262. moment this is only used on iOS and partially on OSX.
  263. On OSX only allow* flags are used and they control remote notifications only.
  264. To control sound, alert and badge settings for local notifications on OSX,
  265. use Notifications settings in System Preferences.
  266. To setup push notifications for current device, provide permissions required,
  267. as well as register categories of notifications you want to support. Each
  268. category needs to have a unique identifier and it can optionally have multiple
  269. actions. Each action also needs to have a unique identifier. The example setup
  270. may look as follows:
  271. @code
  272. using Action = PushNotifications::Settings::Action;
  273. using Category = PushNotifications::Settings::Category;
  274. Action okAction;
  275. okAction.identifier = "okAction";
  276. okAction.title = "OK!";
  277. okAction.style = Action::button;
  278. okAction.triggerInBackground = true;
  279. Action cancelAction;
  280. cancelAction.identifier = "cancelAction";
  281. cancelAction.title = "Cancel";
  282. cancelAction.style = Action::button;
  283. cancelAction.triggerInBackground = true;
  284. cancelAction.destructive = true;
  285. Action textAction;
  286. textAction.identifier = "textAction";
  287. textAction.title = "Enter text";
  288. textAction.style = Action::text;
  289. textAction.triggerInBackground = true;
  290. textAction.destructive = false;
  291. textAction.textInputButtonText = "Ok";
  292. textAction.textInputPlaceholder = "Enter text...";
  293. Category okCategory;
  294. okCategory.identifier = "okCategory";
  295. okCategory.actions = { okAction };
  296. Category okCancelCategory;
  297. okCancelCategory.identifier = "okCancelCategory";
  298. okCancelCategory.actions = { okAction, cancelAction };
  299. Category textCategory;
  300. textCategory.identifier = "textCategory";
  301. textCategory.actions = { textAction };
  302. textCategory.sendDismissAction = true;
  303. PushNotifications::Settings settings;
  304. settings.allowAlert = true;
  305. settings.allowBadge = true;
  306. settings.allowSound = true;
  307. settings.categories = { okCategory, okCancelCategory, textCategory };
  308. @endcode
  309. */
  310. struct Settings
  311. {
  312. using Action = Notification::Action;
  313. /** Describes a category of a notification. Each category has a unique identifier
  314. and a list of associated actions.
  315. Note that the OS may allow only a limited number of actions to be presented, so
  316. always present most important actions first.
  317. */
  318. struct Category
  319. {
  320. juce::String identifier; /**< unique identifier */
  321. juce::Array<Action> actions; /**< optional list of actions within this category */
  322. bool sendDismissAction = false; /**< whether dismiss action will be sent to the app (from iOS 10 only) */
  323. };
  324. bool allowSound = false; /**< whether the app should play a sound upon notification */
  325. bool allowAlert = false; /**< whether the app should present an alert upon notification */
  326. bool allowBadge = false; /**< whether the app may badge its icon upon notification */
  327. Array<Category> categories; /**< list of categories the app wants to support */
  328. };
  329. /** Initialises push notifications on current device with the settings provided.
  330. Call this on your application startup and on iOS the first time the application starts,
  331. a user will be presented with a permission request dialog to give push notifications permission.
  332. Once a user responds, Listener::notificationSettingsReceived() will be called so that
  333. you can check what permissions where actually granted. The listener callback will be called
  334. on each subsequent startup too (provided you called requestPermissionsWithSettings() on previous
  335. application run). This way you can check what are current push notifications permissions.
  336. Note that settings are currently only used on iOS. When calling on other platforms, Settings
  337. with no categories and all allow* flags set to true will be received in
  338. Listener::notificationSettingsReceived().
  339. You can also call requestSettingsUsed() to explicitly ask for current settings.
  340. */
  341. void requestPermissionsWithSettings (const Settings& settings);
  342. /** Sends an asynchronous request to retrieve current settings that are currently in use.
  343. These can be exactly the same as used in requestPermissionsWithSettings(), but depending
  344. on user's subsequent changes in OS settings, the actual current settings may be
  345. different (e.g. user might have later decided to disable sounds).
  346. Note that settings are currently only used on iOS and partially on OSX.
  347. On OSX, only allow* flags are used and they refer to remote notifications only. For
  348. local notifications, refer to System Preferences.
  349. When calling this function on other platforms, Settings with no categories and all allow*
  350. flags set to true will be received in Listener::notificationSettingsReceived().
  351. */
  352. void requestSettingsUsed();
  353. //==============================================================================
  354. /** Android API level 26 or higher only: Represents notification channel through which
  355. notifications will be sent. Starting from Android API level 26, you should call setupChannels()
  356. at the start of your application, before posting any notifications. Then, when sending notifications,
  357. assign a channel to each created notification.
  358. */
  359. struct Channel
  360. {
  361. String identifier; /**< Required: Unique channel identifier. */
  362. String name; /**< Required: User facing name of the channel. */
  363. /** Controls how interruptive the notification posted on this channel are. */
  364. enum Importance
  365. {
  366. none,
  367. min,
  368. low,
  369. normal,
  370. high,
  371. max
  372. };
  373. Importance importance = normal; /**< Required. */
  374. Notification::LockScreenAppearance lockScreenAppearance = Notification::showPartially; /**< Optional. */
  375. String description; /**< Optional: user visible description of the channel. */
  376. String groupId; /**< Required: group this channel belongs to (see ChannelGroup). */
  377. Colour ledColour; /**< Optional: sets the led colour for notifications in this channel. */
  378. bool bypassDoNotDisturb = false; /**< Optional: true if notifications in this channel can bypass do not disturb setting. */
  379. bool canShowBadge = false; /**< Optional: true if notifications in this channel can show badges in a Launcher application. */
  380. bool enableLights = false; /**< Optional: true if notifications in this channel should show lights (subject to hardware support). */
  381. bool enableVibration = false; /**< Optional: true if notifications in this channel should trigger vibrations. */
  382. URL soundToPlay; /**< Optional: sound to play in this channel. See Notification::soundToPlay for more info. */
  383. Array<int> vibrationPattern; /**< Optional: vibration pattern for this channel. See Notification::vibrationPattern for more info. */
  384. };
  385. /** Android API level 26 or higher only: represents a channel group. This allows for
  386. visual grouping of corresponding channels in notification settings presented to the user.
  387. At least one channel group has to be specified before notifications can be sent.
  388. */
  389. struct ChannelGroup
  390. {
  391. String identifier; /**< Required: Unique channel group identifier. */
  392. String name; /**< Required: User visible name of the channel group. */
  393. };
  394. /** Android API level 26 or higher only: configures notification channel groups and channels to be
  395. used in the app. These have to be setup before notifications can be sent on Android API
  396. level 26 or higher.
  397. */
  398. void setupChannels (const Array<ChannelGroup>& groups, const Array<Channel>& channels);
  399. //==============================================================================
  400. /** iOS only: sends an asynchronous request to retrieve a list of notifications that were
  401. scheduled and not yet delivered.
  402. When the list is retrieved, Listener::pendingLocalNotificationsListReceived() will be called.
  403. */
  404. void getPendingLocalNotifications() const;
  405. /** Unschedules a pending local notification with a given identifier. Available from iOS 10. */
  406. void removePendingLocalNotification (const String& identifier);
  407. /** Unschedules all pending local notifications. iOS only. */
  408. void removeAllPendingLocalNotifications();
  409. //==============================================================================
  410. /** Checks whether notifications are enabled for given application.
  411. On iOS and OSX this will always return true, use requestSettingsUsed() instead.
  412. */
  413. bool areNotificationsEnabled() const;
  414. /** On iOS as well as on Android, sends a local notification.
  415. On Android and iOS 10 or above, this will refresh an existing notification
  416. if the same identifier is used as in a notification that was already sent
  417. and not yet responded by a user.
  418. */
  419. void sendLocalNotification (const Notification& notification);
  420. /** Sends a request for a list of notifications delivered. Such notifications are visible in the
  421. notification area on the device and they are still waiting for user action/response.
  422. When the request is finished Listener::deliveredNotificationsListReceived() will be called.
  423. On iOS, iOS version 10 or higher is required. On Android, API level 18 or higher is required.
  424. For unsupported platforms, Listener::deliveredNotificationsListReceived() will return an empty array.
  425. */
  426. void getDeliveredNotifications() const;
  427. /** Removes a previously delivered notification. This can be useful for instance when the
  428. information in the notification becomes obsolete.
  429. */
  430. void removeDeliveredNotification (const String& identifier);
  431. /** Removes all notifications that were delivered. */
  432. void removeAllDeliveredNotifications();
  433. //==============================================================================
  434. /** Retrieves current device token. Note, it is not a good idea to cache this token
  435. because it may change in the meantime. Always call this method to get the current
  436. token value.
  437. */
  438. String getDeviceToken() const;
  439. /** Android only: allows to subscribe to messages from a specific topic.
  440. So you could for instance subscribe this device to all "sports" topic messages
  441. to receive any remote notifications that have "sports" topic set.
  442. Refer to Firebase documentation for how to send topic messages.
  443. */
  444. void subscribeToTopic (const String& topic);
  445. /** Android only: allows to remove a topic subscription that was previously added with
  446. subscribeToTopic().
  447. */
  448. void unsubscribeFromTopic (const String& topic);
  449. /** Android only: sends an upstream message to your app server. The server must implement
  450. XMPP Connection Server protocol (refer to Firebase documentation).
  451. @param serverSenderId Represents the sender. Consult your Firebase project
  452. settings to retrieve the sender id.
  453. @param collapseKey Remote messages with the same collapse key that were not
  454. yet delivered will be collapsed into one, with the
  455. newest message replacing all the previous ones.
  456. Note that there may be a limit of maximum collapse keys
  457. used at the same time and beyond the limit (refer to
  458. Firebase documentation) it is not guaranteed which keys
  459. will be in use by the server.
  460. @param messageId A unique message ID. Used in error callbacks and debugging.
  461. @param messageType Message type.
  462. @param timeToLive TTL in seconds. If 0, the message sending will be attempted
  463. immediately and it will be dropped if the device is not
  464. connected. Otherwise, the message will be queued for the
  465. period specified.
  466. @param additionalData Collection of key-value pairs to be used as an additional
  467. data for the message.
  468. */
  469. void sendUpstreamMessage (const String& serverSenderId,
  470. const String& collapseKey,
  471. const String& messageId,
  472. const String& messageType,
  473. int timeToLive,
  474. const StringPairArray& additionalData);
  475. //==============================================================================
  476. /** Register a listener (ideally on application startup) to receive information about
  477. notifications received and any callbacks to async functions called.
  478. */
  479. struct Listener
  480. {
  481. virtual ~Listener() = default;
  482. /** This callback will be called after you call requestSettingsUsed() or
  483. requestPermissionsWithSettings().
  484. Note that settings are currently only used on iOS. When called on other platforms, Settings
  485. with no categories and all allow flags set to true will be received in
  486. Listener::notificationSettingsReceived().
  487. */
  488. virtual void notificationSettingsReceived (const Settings& settings) { ignoreUnused (settings); }
  489. /** Called when the list of pending notifications, requested by calling
  490. getPendingLocalNotifications() is returned. iOS 10 or above only.
  491. */
  492. virtual void pendingLocalNotificationsListReceived (const Array<Notification>& notifications) { ignoreUnused (notifications); }
  493. /** This can be called in multiple different situations, depending on the OS and the situation.
  494. On pre iOS 10 device it will be called when a user presses on a notification or when a
  495. notification was received when the app was in the foreground already. On iOS 10 it will be
  496. called when a user presses on a notification
  497. Note: On Android, if remote notification was received while the app was in the background and
  498. then user pressed on it, the notification object received in this callback will contain only
  499. "properties" member set. Hence, if you want to know what was the notification title, content
  500. etc, you need to set them as additional properties, so that you will be able to restore them
  501. from "properties" dictionary.
  502. Note you can receive this callback on startup, if the application was launched from a notification.
  503. */
  504. virtual void handleNotification (bool isLocalNotification, const Notification& notification) { ignoreUnused (isLocalNotification); ignoreUnused (notification); }
  505. /** This can be called when a user performs some action on the notification such as
  506. pressing on an action button or responding with a text input.
  507. Note that pressing on a notification area, i.e. not on an action button is not considered
  508. to be an action, and hence receivedNotification() will be called in that case.
  509. Note you can receive this callback on startup, if the application was launched from a notification's action.
  510. @param isLocalNotification If the notification is local
  511. @param notification The notification
  512. @param actionIdentifier A String identifying the action
  513. @param optionalResponse Text response a user inputs for notifications with a text input.
  514. Empty for notifications without a text input option.
  515. */
  516. virtual void handleNotificationAction (bool isLocalNotification,
  517. const Notification& notification,
  518. const String& actionIdentifier,
  519. const String& optionalResponse)
  520. {
  521. ignoreUnused (isLocalNotification);
  522. ignoreUnused (notification);
  523. ignoreUnused (actionIdentifier);
  524. ignoreUnused (optionalResponse);
  525. }
  526. /** For iOS10 and Android, this can be also called when a user dismissed the notification before
  527. responding to it.
  528. */
  529. virtual void localNotificationDismissedByUser (const Notification& notification) { ignoreUnused (notification); }
  530. /** Called after getDeliveredNotifications() request is fulfilled. Returns notifications
  531. that are visible in the notification area on the device and that are still waiting
  532. for a user action/response.
  533. On iOS, iOS version 10 or higher is required. On Android, API level 18 or higher is required.
  534. For unsupported platforms, an empty array will be returned.
  535. */
  536. virtual void deliveredNotificationsListReceived (const Array<Notification>& notifications) { ignoreUnused (notifications); }
  537. /** Called whenever a token gets refreshed. You should monitor any token updates, because
  538. only the last token that is assigned to device is valid and can be used.
  539. */
  540. virtual void deviceTokenRefreshed (const String& token) { ignoreUnused (token); }
  541. /** Called when Firebase Cloud Messaging server deletes pending messages. This can happen when
  542. 1) too many messages were sent to the server (hint: use collapsible messages).
  543. 2) the devices hasn't been online in a long time (refer to Firebase documentation for
  544. the maximum time a message can be stored on FCM before expiring).
  545. */
  546. virtual void remoteNotificationsDeleted() {}
  547. /** Called when an upstream message sent with PushNotifications::sendUpstreamMessage() has been
  548. sent successfully.
  549. Bear in mind that in may take several minutes or more to receive this callback.
  550. */
  551. virtual void upstreamMessageSent (const String& messageId) { ignoreUnused (messageId); }
  552. /** Called when there was an error sending an upstream message with
  553. PushNotifications::sendUpstreamMessage().
  554. Bear in mind that in may take several minutes or more to receive this callback.
  555. */
  556. virtual void upstreamMessageSendingError (const String& messageId, const String& error) { ignoreUnused (messageId); ignoreUnused (error); }
  557. };
  558. void addListener (Listener* l);
  559. void removeListener (Listener* l);
  560. private:
  561. PushNotifications();
  562. ~PushNotifications() override;
  563. ListenerList<PushNotifications::Listener> listeners;
  564. #if JUCE_ANDROID
  565. friend bool juce_handleNotificationIntent (void*);
  566. friend struct JuceFirebaseInstanceIdService;
  567. friend struct JuceFirebaseMessagingService;
  568. #endif
  569. #if JUCE_PUSH_NOTIFICATIONS
  570. struct Pimpl;
  571. friend struct Pimpl;
  572. std::unique_ptr<Pimpl> pimpl;
  573. #endif
  574. };
  575. } // namespace juce