Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions local-notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ For more information about the behavior changes of your app related to the priva
<docgen-config>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

On Android, the Local Notifications can be configured with the following options:
The Local Notifications can be configured with the following options:

| Prop | Type | Description | Since |
| --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| **`smallIcon`** | <code>string</code> | Set the default status bar icon for notifications. Icons should be placed in your app's `res/drawable` folder. The value for this option should be the drawable resource ID, which is the filename without an extension. Only available for Android. | 1.0.0 |
| **`iconColor`** | <code>string</code> | Set the default color of status bar icons for notifications. Only available for Android. | 1.0.0 |
| **`sound`** | <code>string</code> | Set the default notification sound for notifications. On Android 8+ it sets the default channel sound and can't be changed unless the app is uninstalled. If the audio file is not found, it will result in the default system sound being played on Android 7.x and no sound on Android 8+. Only available for Android. | 1.0.0 |
| Prop | Type | Description | Since |
| ------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`smallIcon`** | <code>string</code> | Set the default status bar icon for notifications. Icons should be placed in your app's `res/drawable` folder. The value for this option should be the drawable resource ID, which is the filename without an extension. Only available for Android. | 1.0.0 |
| **`iconColor`** | <code>string</code> | Set the default color of status bar icons for notifications. Only available for Android. | 1.0.0 |
| **`sound`** | <code>string</code> | Set the default notification sound for notifications. On Android 8+ it sets the default channel sound and can't be changed unless the app is uninstalled. If the audio file is not found, it will result in the default system sound being played on Android 7.x and no sound on Android 8+. Only available for Android. | 1.0.0 |
| **`presentationOptions`** | <code>LocalNotificationPresentationOption[]</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 notification is received - `banner`: the notification is displayed as a banner - `list`: the notification is displayed in the notification center An empty array can be provided if none of the options are desired. Only available for iOS. | 8.2.0 |

### Examples

Expand All @@ -54,7 +55,8 @@ In `capacitor.config.json`:
"LocalNotifications": {
"smallIcon": "ic_stat_icon_config_sample",
"iconColor": "#488AFF",
"sound": "beep.wav"
"sound": "beep.wav",
"presentationOptions": ["badge", "sound", "banner", "list"]
}
}
}
Expand All @@ -73,6 +75,7 @@ const config: CapacitorConfig = {
smallIcon: "ic_stat_icon_config_sample",
iconColor: "#488AFF",
sound: "beep.wav",
presentationOptions: ["badge", "sound", "banner", "list"],
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,32 @@ public class LocalNotificationsHandler: NSObject, NotificationHandlerProtocol {
}
}

if let optionsArray = self.plugin?.getConfig().getArray("presentationOptions") as? [String] {
var presentationOptions = UNNotificationPresentationOptions.init()

optionsArray.forEach { option in
switch option {
case "banner":
presentationOptions.insert(.banner)
case "list":
presentationOptions.insert(.list)
case "badge":
presentationOptions.insert(.badge)
case "sound":
presentationOptions.insert(.sound)
default:
print("Unrecognized presentation option: \(option)")
}
}

return presentationOptions
}

return [
.badge,
.sound,
.alert
.banner,
.list
]
}

Expand Down
20 changes: 19 additions & 1 deletion local-notifications/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

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

export type LocalNotificationPresentationOption = 'badge' | 'sound' | 'banner' | 'list';

declare module '@capacitor/cli' {
export interface PluginsConfig {
/**
* On Android, the Local Notifications can be configured with the following options:
* The Local Notifications can be configured with the following options:
*/
LocalNotifications?: {
/**
Expand Down Expand Up @@ -47,6 +49,22 @@ declare module '@capacitor/cli' {
* @example "beep.wav"
*/
sound?: string;

/**
* 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 notification is received
* - `banner`: the notification is displayed as a banner
* - `list`: the notification is displayed in the notification center
*
* An empty array can be provided if none of the options are desired.
*
* Only available for iOS.
*
* @since 8.2.0
* @example ["badge", "sound", "banner", "list"]
*/
presentationOptions?: LocalNotificationPresentationOption[];
};
}
}
Expand Down
Loading