Push Notifications

Prev Next

Overview

Push Notifications in iOS allow you to send timely messages, promotions, or alerts directly to users, even when the app is not running. These notifications help engage and retain users by delivering relevant content at the right time.

Use Case

  1. Purpose:

    • Notify users about updates, reminders, or offers.

    • Drive engagement with direct access to specific app features or content.

  2. Benefits:

    • Maintain user interest and engagement with personalized content.

    • Boost app usage through targeted re-engagement strategies.

Implementation Details

  1. Enable/Disable Push Notifications: Dynamically enable or disable push notifications within the app.

    For Objective-C:

    [[Appoxee shared] disablePushNotifications:NO withCompletionHandler:^(NSError * _Nullable error, id data) {
        if (!error) {
            NSLog(@"Push Notifications Enabled");
        }
    }];
    
    [[Appoxee shared] disablePushNotifications:YES withCompletionHandler:^(NSError * _Nullable error, id data) {
        if (!error) {
            NSLog(@"Push Notifications Disabled");
        }
    }];

    For Swift:

    Appoxee.shared()?.disablePushNotifications(false, withCompletionHandler: { (error, data) in
        if error == nil {
            print("Push Notifications Enabled")
        }
    })
    
    Appoxee.shared()?.disablePushNotifications(true, withCompletionHandler: { (error, data) in
        if error == nil {
            print("Push Notifications Disabled")
        }
    })
  2. Check Push Notification State: Verify if push notifications are enabled or disabled.

    For Objective-C:

    [[Appoxee shared] isPushEnabled:^(NSError * _Nullable error, id data) {
        if (!error) {
            BOOL isEnabled = [(NSNumber *)data boolValue];
            NSLog(@"Push Notifications Enabled: %d", isEnabled);
        }
    }];

    For Swift:

    Appoxee.shared()?.isPushEnabled { (error, data) in
        if error == nil, let isEnabled = data as? Bool {
            print("Push Notifications Enabled: \(isEnabled)")
        }
    }
  3. Request Notification Permissions: Postpone or trigger notification permission requests dynamically.

    For Objective-C:

    [[Appoxee shared] setPostponeNotificationRequest:YES];

    For Swift:

    Appoxee.shared()?.postponeNotificationRequest = true
  4. Show Notification Alert Dialog: Display a custom alert dialog to prompt users for notification permissions.

    Appoxee.shared()?.showNotificationAlertDialog()

Keep in mind:

  • For iOS 10 and above, ensure delegate methods are implemented for UNUserNotificationCenter.

  • Test notification functionality in all app states (foreground, background, and terminated).

  • Provide a clear and compelling reason for users to opt in to notifications.