Skip to content

Notification

Schedule and manage local notifications

Notification allows you to schedule local notifications that appear even when the app is not running.

Use Notification to:

Examples

javascript
let notif = new Notification();
notif.title = "Reminder";
notif.body = "Don't forget to check in!";
await notif.schedule();
javascript
let notif = new Notification();
notif.title = "Daily Reminder";
notif.body = "Time for your daily task";
notif.setDailyTrigger(9, 0, true); // 9:00 AM daily
await notif.schedule();

Properties

identifier

  • Type: String

Unique notification identifier

javascript
notif.identifier

title

  • Type: String

Notification title

javascript
notif.title = "Title"

subtitle

  • Type: String

Notification subtitle

javascript
notif.subtitle = "Subtitle"

body

  • Type: String

Notification body text

javascript
notif.body = "Body text"

preferredContentHeight

  • Type: Double

Preferred content height for custom notification UI

badge

  • Type: NSNumber

App badge number

javascript
notif.badge = 5

threadIdentifier

  • Type: String

Thread identifier for grouping notifications

javascript
notif.threadIdentifier = "group1"

userInfo

  • Type: [String: Any]

Custom user info dictionary

javascript
notif.userInfo = { key: "value" }

sound

  • Type: String

Notification sound

javascript
notif.sound = "default"

openURL

  • Type: String

URL to open when notification is tapped

javascript
notif.openURL = "https://example.com"

scriptName

  • Type: String

Script to run when notification is tapped

javascript
notif.scriptName = "MyScript"

deliveryDate

  • Type: JSValue

Delivery date for delivered notifications

nextTriggerDate

  • Type: JSValue

Next trigger date for scheduled notifications

actions

  • Type: [[String: String]]

Notification actions

Methods

schedule

Schedule the notification

typescript
schedule(callback): void
  • callback - Callback when scheduled

Returns: Promise that resolves when scheduled

Example:

javascript
await notif.schedule()

remove

Remove this notification

typescript
remove(callback): void
  • callback - Callback when removed

Returns: Promise that resolves when removed

Example:

javascript
await notif.remove()

setTriggerDateWithTimestamp

Set trigger date

typescript
setTriggerDateWithTimestamp(timestamp): void
  • timestamp - JavaScript timestamp in milliseconds

Example:

javascript
notif.setTriggerDate(new Date(Date.now() + 60000))

setDailyTrigger

Set daily trigger

typescript
setDailyTrigger(hour, minute, repeats): void
  • hour - Hour (0-23)
  • minute - Minute (0-59)
  • repeats - Whether to repeat daily

Example:

javascript
notif.setDailyTrigger(9, 0, true)

setWeeklyTrigger

Set weekly trigger

typescript
setWeeklyTrigger(weekday, hour, minute, repeats): void
  • weekday - Day of week (1=Sunday, 7=Saturday)
  • hour - Hour (0-23)
  • minute - Minute (0-59)
  • repeats - Whether to repeat weekly

Example:

javascript
notif.setWeeklyTrigger(2, 9, 0, true)

addAction

Add notification action button

typescript
addAction(title, url, destructive): void
  • title - Button title
  • url - URL to open when tapped
  • destructive - Show as destructive action

Example:

javascript
notif.addAction("Open", "myapp://action", false)

allPending

Get all pending notifications

typescript
static allPending(): void

Example:

javascript
let pending = await Notification.allPending()

allDelivered

Get all delivered notifications

typescript
static allDelivered(): void

Example:

javascript
let delivered = await Notification.allDelivered()

removeAllPending

Remove all pending notifications

typescript
static removeAllPending(): void

Example:

javascript
await Notification.removeAllPending()

removeAllDelivered

Remove all delivered notifications

typescript
static removeAllDelivered(): void

Example:

javascript
await Notification.removeAllDelivered()

removePending

Remove specific pending notifications

typescript
static removePending(): void

Example:

javascript
await Notification.removePending(["id1", "id2"])

removeDelivered

Remove specific delivered notifications

typescript
static removeDelivered(): void

Example:

javascript
await Notification.removeDelivered(["id1", "id2"])

resetCurrent

Reset current notification context

typescript
static resetCurrent(): void