Notifications#
flet_onesignal.notifications.OneSignalNotifications
#
OneSignal Notifications namespace.
Provides methods for managing push notification permissions, display, and lifecycle.
Functions#
can_request_permission
async
#
Check if the app can request notification permission.
Returns True if the device has not been prompted for push notification permission already.
Returns:
| Type | Description |
|---|---|
bool
|
True if permission can be requested, False if already prompted. |
clear_all
async
#
Remove all OneSignal notifications from the notification shade.
display
async
#
Allow a notification to be displayed after calling prevent_default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_id
|
str
|
The notification ID from the event. |
required |
get_permission
async
#
Get the current notification permission status.
Returns:
| Type | Description |
|---|---|
bool
|
True if notifications are permitted, False otherwise. |
prevent_default
async
#
Prevent a notification from being displayed when received in foreground.
Call this from the on_foreground_will_display event handler to suppress the notification display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_id
|
str
|
The notification ID from the event. |
required |
register_for_provisional_authorization
async
#
Request provisional authorization for notifications (iOS only).
Provisional authorization allows sending notifications quietly to the Notification Center without prompting the user first.
Returns:
| Type | Description |
|---|---|
bool
|
True if authorization was granted, False otherwise. |
remove_grouped_notifications
async
#
Remove a group of notifications (Android only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str
|
The notification group key to remove. |
required |
remove_notification
async
#
Remove a specific notification (Android only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_id
|
int
|
The Android notification ID to remove. |
required |
request_permission
async
#
Request permission to send push notifications.
This will display the native system prompt to request push notification permission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fallback_to_settings
|
bool
|
If True and permission was previously denied, opens the app settings instead. |
True
|
timeout
|
float
|
Maximum time to wait for user response (in seconds). |
25
|
Returns:
| Type | Description |
|---|---|
bool
|
True if permission was granted, False otherwise. |