Skip to content

Commit f266d2e

Browse files
feat(push-notifications): add banner and list presentation options for iOS (#2529)
1 parent 78bea4c commit f266d2e

4 files changed

Lines changed: 19 additions & 11 deletions

File tree

push-notifications/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ From Android 8.0 (API level 26) and higher, notification channels are supported
8787

8888
You can configure the way the push notifications are displayed when the app is in foreground.
8989

90-
| Prop | Type | Description | Since |
91-
| ------------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
92-
| **`presentationOptions`** | <code>PresentationOption[]</code> | This is an array of strings you can combine. Possible values in the array are: - `badge`: badge count on the app icon is updated (default value) - `sound`: the device will ring/vibrate when the push notification is received - `alert`: the push notification is displayed in a native dialog An empty array can be provided if none of the options are desired. badge is only available for iOS. | 1.0.0 |
90+
| Prop | Type | Description | Since |
91+
| ------------------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
92+
| **`presentationOptions`** | <code>PresentationOption[]</code> | This is an array of strings you can combine. Possible values in the array are: - `badge`: badge count on the app icon is updated (default value) - `sound`: the device will ring/vibrate when the push notification is received - `alert`: **Deprecated on iOS.** Use `banner` and `list` instead. On Android, this value is still used to display the notification. - `banner`: the push notification is displayed as a banner - `list`: the push notification is displayed in the notification center An empty array can be provided if none of the options are desired. badge is only available for iOS. | 1.0.0 |
9393

9494
### Examples
9595

@@ -99,7 +99,7 @@ In `capacitor.config.json`:
9999
{
100100
"plugins": {
101101
"PushNotifications": {
102-
"presentationOptions": ["badge", "sound", "alert"]
102+
"presentationOptions": ["badge", "sound", "alert", "banner", "list"]
103103
}
104104
}
105105
}
@@ -115,7 +115,7 @@ import { CapacitorConfig } from '@capacitor/cli';
115115
const config: CapacitorConfig = {
116116
plugins: {
117117
PushNotifications: {
118-
presentationOptions: ["badge", "sound", "alert"],
118+
presentationOptions: ["badge", "sound", "alert", "banner", "list"],
119119
},
120120
},
121121
};

push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.firebase.messaging.NotificationParams;
2121
import com.google.firebase.messaging.RemoteMessage;
2222
import java.util.Arrays;
23+
import java.util.List;
2324
import org.json.JSONException;
2425
import org.json.JSONObject;
2526

@@ -247,7 +248,8 @@ public void fireNotification(RemoteMessage remoteMessage) {
247248
String body = notification.getBody();
248249
String[] presentation = getConfig().getArray("presentationOptions");
249250
if (presentation != null) {
250-
if (Arrays.asList(presentation).contains("alert")) {
251+
List<String> presentationList = Arrays.asList(presentation);
252+
if (presentationList.contains("alert") || presentationList.contains("banner") || presentationList.contains("list")) {
251253
Bundle bundle = null;
252254
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
253255
try {

push-notifications/ios/Sources/PushNotificationsPlugin/PushNotificationsHandler.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ public class PushNotificationsHandler: NSObject, NotificationHandlerProtocol {
3434

3535
optionsArray.forEach { option in
3636
switch option {
37+
case "banner":
38+
presentationOptions.insert(.banner)
39+
case "list":
40+
presentationOptions.insert(.list)
3741
case "alert":
38-
presentationOptions.insert(.alert)
42+
presentationOptions.insert(.banner)
43+
presentationOptions.insert(.list)
3944
case "badge":
4045
presentationOptions.insert(.badge)
41-
4246
case "sound":
4347
presentationOptions.insert(.sound)
4448
default:

push-notifications/src/definitions.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import type { PermissionState, PluginListenerHandle } from '@capacitor/core';
44

5-
export type PresentationOption = 'badge' | 'sound' | 'alert';
5+
export type PresentationOption = 'badge' | 'sound' | 'alert' | 'banner' | 'list';
66

77
declare module '@capacitor/cli' {
88
export interface PluginsConfig {
@@ -14,14 +14,16 @@ declare module '@capacitor/cli' {
1414
* This is an array of strings you can combine. Possible values in the array are:
1515
* - `badge`: badge count on the app icon is updated (default value)
1616
* - `sound`: the device will ring/vibrate when the push notification is received
17-
* - `alert`: the push notification is displayed in a native dialog
17+
* - `alert`: **Deprecated on iOS.** Use `banner` and `list` instead. On Android, this value is still used to display the notification.
18+
* - `banner`: the push notification is displayed as a banner. On Android, defaults to the same behavior as `alert`.
19+
* - `list`: the push notification is displayed in the notification center. On Android, defaults to the same behavior as `alert`.
1820
*
1921
* An empty array can be provided if none of the options are desired.
2022
*
2123
* badge is only available for iOS.
2224
*
2325
* @since 1.0.0
24-
* @example ["badge", "sound", "alert"]
26+
* @example ["badge", "sound", "alert", "banner", "list"]
2527
*/
2628
presentationOptions: PresentationOption[];
2729
};

0 commit comments

Comments
 (0)