Notifications
Send native notifications to your user using the notification plugin.
Supported Platforms
This plugin requires a Rust version of at least 1.77.2
Platform | Level | Notes |
---|---|---|
windows | Only works for installed apps. Shows powershell name & icon in development. | |
linux | ||
macos | ||
android | ||
ios |
Setup
Install the notifications plugin to get started.
Usage
Here are a few examples of how to use the notification plugin:
- Send notification to users
- Add an action to a notification
- Add an attachment to a notification
- Send a notification in a specific channel
The notification plugin is available in both JavaScript and Rust.
Send Notification
Follow these steps to send a notification:
-
Check if permission is granted
-
Request permission if not granted
-
Send the notification
Actions
Actions add interactive buttons and inputs to notifications. Use them to create a responsive experience for your users.
Register Action Types
Register action types to define interactive elements:
Action Properties
Property | Description |
---|---|
id | Unique identifier for the action |
title | Display text for the action button |
requiresAuthentication | Requires device authentication |
foreground | Brings app to foreground when triggered |
destructive | Shows action in red on iOS |
input | Enables text input |
inputButtonTitle | Text for input submit button |
inputPlaceholder | Placeholder text for input field |
Listen for Actions
Listen to user interactions with notification actions:
Attachments
Attachments add media content to notifications. Support varies by platform.
Attachment Properties
Property | Description |
---|---|
id | Unique identifier |
url | Content URL using asset:// or file:// protocol |
Note: Test attachments on your target platforms to ensure compatibility.
Channels
Channels organize notifications into categories with different behaviors. While primarily used on Android, they provide a consistent API across platforms.
Create a Channel
Channel Properties
Property | Description |
---|---|
id | Unique identifier |
name | Display name |
description | Purpose description |
importance | Priority level (None, Min, Low, Default, High) |
visibility | Privacy setting (Secret, Private, Public) |
lights | Enable notification LED (Android) |
lightColor | LED color (Android) |
vibration | Enable vibrations |
sound | Custom sound filename |
Managing Channels
List existing channels:
Remove a channel:
Using Channels
Send a notification using a channel:
Note: Create channels before sending notifications that reference them. Invalid channel IDs prevent notifications from displaying.
Security Considerations
Aside from normal sanitization procedures of user input there are currently no known security considerations.
Default Permission
This permission set configures which notification features are by default exposed.
Granted Permissions
It allows all notification related features.
allow-is-permission-granted
allow-request-permission
allow-notify
allow-register-action-types
allow-register-listener
allow-cancel
allow-get-pending
allow-remove-active
allow-get-active
allow-check-permissions
allow-show
allow-batch
allow-list-channels
allow-delete-channel
allow-create-channel
allow-permission-state
Permission Table
Identifier | Description |
---|---|
|
Enables the batch command without any pre-configured scope. |
|
Denies the batch command without any pre-configured scope. |
|
Enables the cancel command without any pre-configured scope. |
|
Denies the cancel command without any pre-configured scope. |
|
Enables the check_permissions command without any pre-configured scope. |
|
Denies the check_permissions command without any pre-configured scope. |
|
Enables the create_channel command without any pre-configured scope. |
|
Denies the create_channel command without any pre-configured scope. |
|
Enables the delete_channel command without any pre-configured scope. |
|
Denies the delete_channel command without any pre-configured scope. |
|
Enables the get_active command without any pre-configured scope. |
|
Denies the get_active command without any pre-configured scope. |
|
Enables the get_pending command without any pre-configured scope. |
|
Denies the get_pending command without any pre-configured scope. |
|
Enables the is_permission_granted command without any pre-configured scope. |
|
Denies the is_permission_granted command without any pre-configured scope. |
|
Enables the list_channels command without any pre-configured scope. |
|
Denies the list_channels command without any pre-configured scope. |
|
Enables the notify command without any pre-configured scope. |
|
Denies the notify command without any pre-configured scope. |
|
Enables the permission_state command without any pre-configured scope. |
|
Denies the permission_state command without any pre-configured scope. |
|
Enables the register_action_types command without any pre-configured scope. |
|
Denies the register_action_types command without any pre-configured scope. |
|
Enables the register_listener command without any pre-configured scope. |
|
Denies the register_listener command without any pre-configured scope. |
|
Enables the remove_active command without any pre-configured scope. |
|
Denies the remove_active command without any pre-configured scope. |
|
Enables the request_permission command without any pre-configured scope. |
|
Denies the request_permission command without any pre-configured scope. |
|
Enables the show command without any pre-configured scope. |
|
Denies the show command without any pre-configured scope. |
© 2024 Tauri Contributors. CC-BY / MIT