pub struct Notification<R: Runtime>(/* private fields */);Expand description
Access to the notification APIs.
You can get an instance of this type via NotificationExt
Implementations§
Source§impl<R: Runtime> Notification<R>
impl<R: Runtime> Notification<R>
Sourcepub fn builder(&self) -> NotificationBuilder<R>
pub fn builder(&self) -> NotificationBuilder<R>
Creates a new builder for a notification.
§Examples
use tauri_plugin_notification::NotificationExt;
fn notify<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
app.notification()
.builder()
.title("Tauri")
.body("Tauri is awesome!")
.show()
.unwrap();
}Sourcepub fn request_permission(&self) -> Result<PermissionState>
pub fn request_permission(&self) -> Result<PermissionState>
Requests the permission to send notifications, prompting the user when it was not decided yet.
On Android this requests the POST_NOTIFICATIONS runtime permission.
Sourcepub fn permission_state(&self) -> Result<PermissionState>
pub fn permission_state(&self) -> Result<PermissionState>
Checks the current state of the permission to send notifications without prompting the user.
Sourcepub fn register_action_types(&self, types: Vec<ActionType>) -> Result<()>
pub fn register_action_types(&self, types: Vec<ActionType>) -> Result<()>
Registers the action types a notification can reference
through NotificationBuilder::action_type_id.
§Platform-specific
- Android: only the identifier, title and input flag of each
Actionare used. - iOS: each action type is registered as a
UNNotificationCategory.
Sourcepub fn on_action<F: Fn(&ActionPerformed) + Send + Sync + 'static>(
&self,
handler: F,
) -> Result<()>
pub fn on_action<F: Fn(&ActionPerformed) + Send + Sync + 'static>( &self, handler: F, ) -> Result<()>
Calls handler for every action the user performs on a notification of this app:
a tap on the notification itself (tap) or on one of its actions.
§Errors
Returns an error when the listener could not be registered with the mobile plugin.
Sourcepub fn remove_active(&self, notifications: Vec<i32>) -> Result<()>
pub fn remove_active(&self, notifications: Vec<i32>) -> Result<()>
Removes the delivered notifications with the given identifiers from the notification center.
Use Self::remove_all_active to remove every delivered notification.
Sourcepub fn active(&self) -> Result<Vec<ActiveNotification>>
pub fn active(&self) -> Result<Vec<ActiveNotification>>
Lists the notifications that were delivered and are still visible in the notification center.
Sourcepub fn remove_all_active(&self) -> Result<()>
pub fn remove_all_active(&self) -> Result<()>
Removes all delivered notifications from the notification center.
Sourcepub fn pending(&self) -> Result<Vec<PendingNotification>>
pub fn pending(&self) -> Result<Vec<PendingNotification>>
Lists the scheduled notifications that have not been delivered yet.
Sourcepub fn cancel_all(&self) -> Result<()>
pub fn cancel_all(&self) -> Result<()>
Cancel all pending notifications.
Sourcepub fn create_channel(&self, channel: Channel) -> Result<()>
pub fn create_channel(&self, channel: Channel) -> Result<()>
Creates a notification channel, which notifications can target
through NotificationBuilder::channel_id.
Notifications that reference a channel that does not exist are not delivered.
Only available on Android.
Sourcepub fn delete_channel(&self, id: impl Into<String>) -> Result<()>
pub fn delete_channel(&self, id: impl Into<String>) -> Result<()>
Deletes the notification channel with the given identifier.
Only available on Android.
Sourcepub fn list_channels(&self) -> Result<Vec<Channel>>
pub fn list_channels(&self) -> Result<Vec<Channel>>
Lists the notification channels that are currently registered for the app.
Only available on Android.