Push Notification Permission Request

Helps customers to enable push on the device

Description

The requestPushPermission() action triggers the native permission prompt on the user's device, allowing your app to request access to system-level features such as Push Notifications.

This action is primarily used to prompt the user to enable push notifications so they can receive order updates, promotional alerts, and other timely messages from the app.

When invoked, the device will display the OS-native permission page (iOS/Android), and the user will be able to accept or deny the request.

Function Signature

VajroSDK.actions.requestPushPermission()

Structure of Response

StatusResponse
Success{ "status": "success", "message": "Popup showed" }
Failed{ "status": "failed", "message": "Unable to show popup" }
Unexpected Error{ "status": "error", "errorId": 500, "errorHandle": "unknown-error", "message": "Something unexpected happened" }

Example Usage

const permission = VajroSDK.variables.device.permissions.notification;
document.getElementById("test_data_visibility").innerHTML += permission;
if (permission == "denied") {
    VajroSDK.actions.showToast({
        title: "Oops!!",
        message: "Please enable Push."
    });
    VajroSDK.actions.requestPushPermission();
} else {
    VajroSDK.actions.showToast({
        title: "YAAY!!",
        message: "Push Enabled"
    });
}

Best Practices

  1. Check existing permission state first using Vajro.variables.device.permissions to avoid unnecessary prompts.
  2. Explain why permission is needed before calling requestPermissions() (e.g., show a modal or message first).
  3. Request permissions at meaningful moments, e.g., during onboarding or after a user action — not immediately on page load.
  4. Use this action for push notifications only, unless other permissions are officially documented.
  5. Provide fallback UI when permission is denied (e.g., “Enable notifications from Settings”).

Caveats

  1. The SDK does not return the user’s choice instantly — use permissions variable on next app load or after app resumes.
  2. Avoid prompting too frequently, as it may lead to negative user experience.