Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Trigger Push Prompt Programmatically

Need to ask your users for push notification permission at just the right moment? We've got you covered! This guide shows you how to trigger the push notification prompt whenever it makes sense for your users.

The Quick Version

You can trigger the push notification prompt with a simple method:

nativeFunctions.triggerPushPrompt()

What Happens When You Call It?

Here's something important to know: iOS and Android handle push permission requests differently after a user has declined them once:

  • First-time requests: When a user hasn't responded to a push notification prompt before, calling triggerPushPrompt() will show the native system permission dialog.
  • After declining: If a user has previously declined notifications, the function is smart enough to redirect them to the system settings page for your app! This happens because both iOS and Android prevent apps from showing the permission prompt multiple times after a user says "no." Instead of hitting a dead end, your users will be taken right where they need to go to enable notifications manually.

This behavior means you don't have to worry about handling different permission states - the function adapts automatically to give users the right path forward!

Show Me the Code!

Here's a snippet that you can drop into your app to create a smart notification prompt button:

// First, check if we're running in Canvas
if (navigator.userAgent.toLowerCase().includes('canvas')) {
  // Let's grab user info from wherever it's available
  var userObject = null;
  
  // Try iOS method first
  if (window.mobiloudAppInfo) {
    userObject = window.mobiloudAppInfo;
  } 
  // If that doesn't work, try the Android method
  else if (nativeFunctions.getDeviceInfo) {
    userObject = nativeFunctions.getDeviceInfo();
  }
  
  // Only show the button if the user hasn't subscribed yet
  if (userObject && userObject.pushSubscribed === false) {
    // Add a push notification button to your page
    document.write('<button onclick="nativeFunctions.triggerPushPrompt()">Get Notified!</button>');
  }
}

What's in the User Object?

When you get device info, you'll receive an object packed with useful stuff:

{
  appId: string,          // Your app's ID
  appVersion: string,     // The version of your app
  brand: string,          // Device brand name
  hardware: string,       // What's under the hood
  manufacturer: string,   // Who made the device
  model: string,          // Device model
  nameos: string,         // OS name
  osVersion: string,      // OS version number
  platform: string,       // iOS or Android
  pushSubscribed: boolean, // The important bit! Is the user subscribed?
  pushToken: string,      // User's push token
  pushUserId: string,     // User ID for push services
  timeZone: string        // User's local time zone
}

Tips for Success

  • Timing is everything! Ask for permissions when users actually see the value of notifications
  • Give context – let users know what kind of notifications they'll get and why they matter
  • Test on real devices to make sure everything works smoothly across platforms

Ready to boost your engagement with perfectly-timed push notifications? Let's do this! 🚀