How to Prompt for Push Permissions with an In-App Message

Use in-app messages to prompt users to subscribe to push notifications the right way.

Both Apple's Human Interface Guidelines and Google's developer documentation highly recommend providing context for the type of information that will be sent and its value, when asking for push notification permission, and offering users a clear way to opt-out.

iOS allows their native push prompt to be shown one time. It cannot be re-shown if dismissed or if previously allowed. If it was shown in the past, the user must be sent to their phone settings to enable notifications.

Android allows its native push prompt to be shown up to two times. Prompting only happens for Android 13 or newer devices, since older devices are opted-in by default.

Regardless, using OneSignal's In-App Messages, you can easily create and customize a "soft-prompt" to ask users to grant your app permission to send push notifications. If the user selects “Allow”, the system’s push permission prompt appears. Otherwise, the in-app message will be closed. However, prompting too often can result in a bad user experience for your users.

Preparing for Setup

Before getting set up, check that you do not show the native prompt:

  • if present, remove the push prompting methods.
  • if present, remove any other reference to iOS native API requestAuthorizationWithOptions.
  • if present, remove any other reference to Android native API requestPermissions with android.permission.POST_NOTIFICATIONS

Also, make sure you have the latest version of the OneSignal SDK in your app.

Set Up The In-App Message

In Messages > In-App edit the default Push Permission Prompt template or create your own with the New In-App button.

15121512

Select the dropdown to create a new in-app message.

Keep the Audience set to "all users". Paid Plans allow targeting segments. You can select Show to Particular Segment(s) if you want to only prompt under certain conditions using Segments.

21322132

Set Up Your Message

In-App Messages can be customized to your app's theme and how you like to communicate. Use any wording to ask your users to subscribe and gauge their interest. For more details see Design Your In-App Message.

17601760

The in-app message block editor allows you to create message asking users to opt in to push notifications.

Add Buttons

If not using the default template, create a button and select Add Click Action > Push Permission Prompt. When this button is clicked, OneSignal will automatically trigger the native Push Permission Prompt.

In-App Messages that have a Push Permission Prompt button will not be shown to users who have already allowed notifications.

If users have previously denied push permission when shown the native prompt, this button will open the device settings for your app.

To target Android 13+ users, ensure you are using a version of the OneSignal SDK released after July 2022. Follow the Android 13 Push Notification Developer Update Guide.

See the IAM Click Actions guide for more details on adding a Push Permission Prompt, Location Permission Prompt, and more.

670670

The in-app message block editor allows you to add a click action to a button to prompt for push permission.

Triggers

Select the On app open or set the Session Duration trigger to a time of your choosing to determine when users will see the in-app message.

17521752

Triggers can be set to time when users see the in-app message.

You can also set programmatic triggers when the user clicks a button or visits a certain page of your app for example. Under the Triggers section select In-App Trigger and set prompt_notification is true.

12601260

Option to use a programmatic trigger.

In your app's code, use the OneSignal addTrigger SDK method to show the prompt. For example:

// OneSignal iOS SDK 3.x.x+
if let deviceState = OneSignal.getDeviceState() {
  let subscribed = deviceState.isSubscribed
  if subscribed == false {
    OneSignal.addTrigger("prompt_ios", withValue: "true")
  }
 }
// OneSignal iOS SDK 3.x.x+
OSDeviceState *deviceState = [OneSignal getDeviceState];
BOOL subscribed = deviceState.isSubscribed;
if (subscribed == false) {
    [OneSignal addTrigger:@"prompt_ios" withValue:@"true"];
}
// OneSignal React Native SDK 4.x.x+
const deviceState = OneSignal.getDeviceState();
if (deviceState.isSubscribed == false) {
  OneSignal.addTrigger("prompt_ios", "true");
}
var currentStatus = OneSignal.Default.NotificationPermission;
if (currentStatus == NotificationPermission.NotDetermined) {
    OneSignal.Default.SetTrigger("prompt_ios", "true");
}
// Ionic 5 Capacitor may need to use (window as any).plugins.OneSignal
window.plugins.OneSignal.addTrigger("prompt_ios", "true");
OneSignal.shared.addTrigger("prompt_ios", "true");
private void IdsAvailable(string userID, string pushToken) {
  print("UserID:"  + userID);
  print("pushToken:" + pushToken);
  if pushToken == null {
    OneSignal.AddTrigger("prompt_ios", "true");
  }
}

Schedule and Re-Trigger

Finally, you can schedule the message to start showing after a certain date.

How often do you want to show this message?

If you are testing or using programmatic triggers, we recommend selecting the Every time trigger conditions are satisfied to show it whenever the triggers are met.

If you are using the On app open or Session Duration, try the Multiple times with 9999 and a gap of 1 week in between. The first number is how many times you want the message to show and the 2nd number is the timeframe in which to wait before showing the message again.

In this case, if the user is already subscribed, they will not see the message again until they are unsubscribed.

This can always be changed later based on how often you want to prompt for push.

17421742

Schedule when users will start seeing your in-app message and how often they see it.

👍

Done!

Select Update or Make Message Live.

Any unsubscribed devices will now be prompted.


Programmatically Triggering the Native Permission Prompt

Not Recommended: use the OneSignal Push Prompt methods to trigger the Permission Prompt. It is recommended to use the above or your own soft-prompt first before triggering this method.


Did this page help you?