On iOS, apps can handle and display push alerts (including sounds and badges) only if the users expressed consent to receive them.


By default, Carnival will ask the user to opt-in for push notifications as soon as you call Carnival.startEngine(). On the other hand, sophisticated apps may want to control when to show the push prompt during their welcome experiences; this way, users can first understand the value of enabling push notifications, and then they will be prompted using the native iOS dialog.

You can prevent the default behavior by delaying the push prompt in the following way.

1. Delaying the push prompt

As usual, start the Carnival engine as early as possible in your app's lifecycle. Change the Carnival.startEngine() call to inform the engine you don't want to register the user for push notifications right away:

Carnival.startEngine(appKey: APP_KEY, registerForPushNotifications: false)

if UIApplication.shared.isRegisteredForRemoteNotifications {
  // Register for push notifications here
// Call startEngine and pass in NO for registerForPushNotifications
[Carnival startEngine:APP_KEY registerForPushNotifications:NO];

// Ensure that push notifications are requested *IF* the user has accepted this in the past
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
    // Register for push notifications in this block      
        // Apple recommends to request a new push token every launch
        // https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW14

2. Requesting push permission from the user

When you are ready to ask the user for push permission (for example as part of the welcome expedience), you can summon Apple's push dialog directly:

let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.badge, .alert, .sound]) { (granted, error) in
  if error != nil {
    // Handle errors here
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge + UNAuthorizationOptionAlert +  UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
    if (error != nil) {
      // Handle errors here