The Despia Request Push Permission SDK enables your application to request push notification permissions from users who have previously deactivated them. This provides a simple way to re-engage users and ensure they receive important updates from your application.
Quick Start
1. Request Push Permission
Request push notification permissions from the user with a simple command.
// Request push permission
window.despia = "registerpush://"
How It Works
The SDK provides a lightweight solution to request push notification permissions from users who have previously denied them. When invoked, it prompts the user with a permission dialog to enable push notifications for your application, following the device's native permission flow.
Checking Push Notification Status with OneSignal
If you have OneSignal enabled (view OneSignal documentation for implementation details), you can check if push notifications are enabled by verifying the OneSignal Player ID:
// Check if push notifications are enabled with OneSignal
if (window.onesignalplayerid && window.onesignalplayerid.length > 0) {
console.log("Push notifications are enabled");
// Run any logic needed when the user has push notifications enabled
} else {
console.log("Push notifications are not enabled or OneSignal is not being used");
// Prompt the user to allow push notifications
window.despia = "registerpush://"
}
When the onesignalplayerid length is greater than 0, it means the user has push notifications enabled. If the length is 0, it either means notifications are not enabled or you are not using OneSignal.
Implementation Examples
Below is a basic implementation example for requesting push notification permissions:
// Request push permission
window.despia = "registerpush://"
Best Practices
User Experience
-
Wait for user interaction before requesting
-
Explain the value of notifications first
-
Handle denied permissions gracefully
Technical Implementation
-
Don't request too frequently
-
Test on real mobile devices not simulators
Troubleshooting
Common Issues
Permission Denied
-
Explain the benefits clearly to users
-
Wait for appropriate context before requesting again
-
Provide alternative communication channels
For additional support or questions, please contact our support team at support@despia.com