Notice for App Developers

Android setup:

On APIs 33 and higher (Android 13+), requires adding permission on the application's AndroidManifest.xml file:

<manifest [...]>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
[...]
</manifest>

Hierarchy

  • Notification

Methods

  • Checks the status of the notification permission.

    🚨 Android will not respond as "blocked" when checked; instead, you need to make a request to obtain the information.

    Example:

    let checkPermissionResult = await Eitri.notification.checkPermission()
    console.log(checkPermissionResult)

    /* Example output from this console.log:
    { status: "DENIED" }
    */

    Compatibility Control

    • API LEVEL 7 - Functionality added

    Returns Promise<NotificationPermissionOutput>

  • Check the permission status for scheduling local notifications.

    Example:

    let checkPermissionResult = await Eitri.notification.checkSchedulePermission()
    console.log(checkPermissionResult)

    /* Example output from this console.log:
    { status: "DENIED" }
    */

    Compatibility Control

    • API LEVEL 20 - Functionality added

    Returns Promise<NotificationPermissionOutput>

  • Requests the permission for scheduling local notifications.

    Example:

    let requestPermissionResult = await Eitri.notification.requestSchedulePermission()
    console.log(requestPermissionResult)

    /* Example output from this console.log:
    { status: "DENIED" }
    */

    Compatibility Control

    • API LEVEL 20 - Functionality added

    Returns Promise<NotificationPermissionOutput>

  • Schedule a local notification on device

    Notice for App Developers

    🚨 Android 12 or higher requires SCHEDULE_EXACT_ALARM permission to send notifications.

    <manifest [...]>
    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
    [...]
    </manifest>

    🚨 iOS require UNUserNotificationCenterDelegate to receive scheduled local notifications when the app is in the foreground.

    func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    didReceive response: UNNotificationResponse,
    withCompletionHandler completionHandler: @escaping () -> Void
    ){
    // you can retrieve the deeplink by accessing the "url" property of the userInfo object
    guard let deeplink = response.notification.request.content.userInfo["url"] as? String else { return }
    ...
    }

    For this method to work, you will first need to have both the permissions for sending notifications and for scheduling.

    Their statuses can be verified with checkPermission and checkSchedulePermission, and be obtained by prompting the user with requestPermission and requestSchedulePermission.

    Example:

    try {

    let notificationPermission = await Eitri.notification.checkPermission();
    if (notificationPermission.status !== "GRANTED") {
    // prepare user for answering the permission request
    const status = await Eitri.notification.requestPermission();
    if (status !== "GRANTED") {
    // notify user that they need to enable notifications
    throw new Error("Notification permission denied");
    }
    }

    let schedulePermission = await Eitri.notification.checkSchedulePermission();
    if (schedulePermission.status !== "GRANTED") {
    // prepare user for answering the permission request
    const status = await Eitri.notification.requestSchedulePermission();
    if (status !== "GRANTED") {
    // notify user that they need to enable notification scheduling
    throw new Error("Schedule permission denied");
    }
    schedulePermission.status = status;
    }

    await Eitri.notification.sendLocalPush({
    id: "1",
    title: "TITLE",
    message: "MESSAGE",
    delayInMilliseconds: 1000 * 10,
    deeplink: "eitri://run/eitri-doctor"
    });

    } catch(error) {
    console.log("sendLocalPush.error: ", error)
    }

    Compatibility Control

    • API LEVEL 20 - Functionality added

    Parameters

    Returns Promise<void>

  • List pending scheduled notifications.

    Example:

    let localPushes = await Eitri.notification.listLocalPushes();
    console.log(localPushes);

    /* Example output from this console.log:
    {
    schedules: [
    { nextOccurrence: "Feb 14, 2025 4:07:58 PM", notification: {...} },
    { nextOccurrence: "Feb 15, 2025 10:00:00 AM", notification: {...} }
    ]
    }
    */

    Compatibility Control

    • API LEVEL 21 - Functionality added

    Returns Promise<NotificationSchedules>

  • Cancel a specific pending scheduled notification.

    Example:

    await Eitri.notification.cancelLocalPush({ id: "1" });
    

    Compatibility Control

    • API LEVEL 21 - Functionality added

    Parameters

    Returns Promise<void>

Generated using TypeDoc