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
| Status | Response |
|---|---|
| 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
- Check existing permission state first using Vajro.variables.device.permissions to avoid unnecessary prompts.
- Explain why permission is needed before calling requestPermissions() (e.g., show a modal or message first).
- Request permissions at meaningful moments, e.g., during onboarding or after a user action — not immediately on page load.
- Use this action for push notifications only, unless other permissions are officially documented.
- Provide fallback UI when permission is denied (e.g., “Enable notifications from Settings”).
Caveats
- The SDK does not return the user’s choice instantly — use permissions variable on next app load or after app resumes.
- Avoid prompting too frequently, as it may lead to negative user experience.
Updated about 2 months ago