NotificationManager

The NotificationManager handles all notification operations: pushing, scheduling, querying, canceling, and responding to user actions. Access it via app.notifications.

app.notifications.push(nib.Notification(title="Hello", body="World"))

Methods

Permission

request_permission()

Ask the user for notification permission. The first call shows the system dialog and waits for the answer; later calls return the saved one.

app.notifications.request_permission() -> bool

Returns True when notifications may be shown. Like every query here it blocks, and raises nib.NotConnectedError before the runtime is connected.

Push

push(notification)

Push a notification for immediate delivery.

app.notifications.push(notification: Notification) -> str
Parameter Type Description
notification Notification The notification to deliver immediately

Returns the notification ID.

Schedule

schedule(notification, at)

Schedule a notification for delivery at a specific date and time. If the target time is in the past, the notification is pushed immediately.

app.notifications.schedule(notification: Notification, at: datetime) -> str
Parameter Type Description
notification Notification The notification to schedule
at datetime The date and time when the notification should be delivered

Returns the notification ID.

reschedule(notification, at)

Cancel an existing notification and schedule it for a new time.

app.notifications.reschedule(notification: Notification, at: datetime) -> str
Parameter Type Description
notification Notification The notification to reschedule (must have the same id as the original)
at datetime The new delivery time

Returns the notification ID.

schedule_daily(notification, from_time, to_time, count, from_date, to_date)

Schedule a notification that recurs daily. Supports time windows, multiple notifications per day, and date ranges.

app.notifications.schedule_daily(
    notification: Notification,
    from_time: str,
    to_time: str | None = None,
    count: int = 1,
    from_date: date | None = None,
    to_date: date | None = None,
) -> str
Parameter Type Default Description
notification Notification none The notification to schedule
from_time str none Start time in "HH:MM" format (e.g., "08:00")
to_time str | None None Optional end time in "HH:MM" format
count int 1 Number of notifications per day
from_date date | None None Optional start date for the schedule
to_date date | None None Optional end date for the schedule

Returns the notification ID.

Cancel

cancel_notification(id)

Cancel a specific notification by its ID. Works for both scheduled (pending) and delivered notifications.

app.notifications.cancel_notification(id: str) -> None
Parameter Type Description
id str The notification ID to cancel

cancel_all_notifications()

Cancel all scheduled notifications and remove all delivered notifications from Notification Center.

app.notifications.cancel_all_notifications() -> None

Query

scheduled(id=None)

The pending notifications (scheduled but not yet delivered), or one of them by id.

app.notifications.scheduled() -> list[Notification]
app.notifications.scheduled(id: str) -> Notification | None
Parameter Type Default Description
id str | None None A notification id. With one, the result is that notification, or None when it is not scheduled

delivered(id=None)

The delivered notifications still visible in Notification Center, or one of them by id.

app.notifications.delivered() -> list[Notification]
app.notifications.delivered(id: str) -> Notification | None
Parameter Type Default Description
id str | None None A notification id. With one, the result is that notification, or None when it is not showing

Both block until the runtime answers, like a service call.

Action Handling

on_action(callback)

Register a handler for notification action callbacks. Called when the user interacts with a notification (taps an action button, types a reply, or clicks the notification itself).

app.notifications.on_action(
    callback: Callable[[str, str, str | None], None]
) -> Subscription
Parameter Type Description
callback Callable[[str, str, str | None], None] Function called with (notification_id, action_id, user_text). user_text is the text entered if the action has a text_input field, otherwise None

Returns a Subscription; its stop() removes the handler.

Built-in action IDs:

Action ID When
"default" User clicked the notification body
"dismiss" User dismissed the notification
Custom ID User tapped a custom action button

Examples

Push and schedule notifications

import nib
from datetime import datetime, timedelta

def main(app: nib.App):
    app.title = "Reminders"
    app.icon = nib.SFSymbol("bell.fill")
    app.width = 320
    app.height = 200

    status = nib.Text("Ready", foreground_color=nib.Color.SECONDARY)

    # Request permission on startup
    granted = app.notifications.request_permission()
    status.content = "Permission granted" if granted else "Permission denied"

    def push_now():
        app.notifications.push(
            nib.Notification(title="Instant", body="Delivered right now!")
        )
        status.content = "Notification pushed"

    def schedule_later():
        n = nib.Notification(title="Reminder", body="Time to take a break!")
        app.notifications.schedule(n, at=datetime.now() + timedelta(seconds=30))
        status.content = f"Scheduled for 30s (ID: {n.id[:8]}...)"

    def cancel_all():
        app.notifications.cancel_all_notifications()
        status.content = "All notifications cancelled"

    app.build(
        nib.VStack(
            controls=[
                nib.Text("Reminders", font=nib.Font.HEADLINE),
                nib.HStack(
                    controls=[
                        nib.Button("Push Now", on_click=push_now),
                        nib.Button("In 30s", on_click=schedule_later),
                    ],
                    spacing=8,
                ),
                nib.Button("Cancel All", on_click=cancel_all, role=nib.ButtonRole.DESTRUCTIVE),
                status,
            ],
            spacing=12,
            padding=20,
        )
    )

nib.run(main)

Handle action callbacks

import nib

def main(app: nib.App):
    app.title = "Chat"
    app.icon = nib.SFSymbol("message.fill")
    app.width = 320
    app.height = 180

    last_reply = nib.Text("No replies yet", foreground_color=nib.Color.SECONDARY)

    def on_action(notification_id, action_id, user_text):
        if action_id == "reply" and user_text:
            last_reply.content = f"You replied: {user_text}"
        elif action_id == "mark_read":
            last_reply.content = "Marked as read"
        elif action_id == "default":
            last_reply.content = "Notification clicked"

    app.notifications.on_action(on_action)
    app.notifications.request_permission()

    def send_message():
        app.notifications.push(
            nib.Notification(
                title="New Message",
                body="Alice: Want to grab lunch?",
                sound=nib.NotificationSound(),
                actions=[
                    nib.NotificationAction(
                        id="reply",
                        title="Reply",
                        text_input=nib.TextInputNotificationAction(
                            button_title="Send",
                            placeholder="Type reply...",
                        ),
                    ),
                    nib.NotificationAction(id="mark_read", title="Mark as Read"),
                ],
            )
        )

    app.build(
        nib.VStack(
            controls=[
                nib.Button("Simulate Message", on_click=send_message,
                           style=nib.ButtonStyle.BORDERED_PROMINENT),
                last_reply,
            ],
            spacing=12,
            padding=20,
        )
    )

nib.run(main)