Notification Center

A popular feature of modern iOS apps is an in-app “Notification Center”. The Notification Center provides the user with an easy way to access the notifications delivered by your app from within your app itself. The Rover SDK provides a turn-key implementation of a Notification Center that you can add to your application with a few simple steps.


Presenting the Notification Center

The RoverNotifications module contains a view controller with everything needed to fetch and display the user’s notifications in a familiar list view. Additionally it supports functionality for marking notifications as read and allowing the user to delete notifications when they are no longer needed.

The only step required to add the Notification Center to your app is to resolve the view controller and present it in response to some user interaction. The most common implementations are to present the Notification Center modally in response to a button tap or as one of the tabs in a tab bar.

Presenting Modally

The following example demonstrates how to present the Notification Center in response to a button tap.

class MyViewController: UIViewController {

    // An IBAction connected to a UIButton through Interface Builder
    @IBAction func presentNotificationCenter(_ sender: Any) {

        // Resolve the Notification Center view controller
        guard let notificationCenter = Rover.shared?.resolve(UIViewController.self, name: "notificationCenter") else {
            return
        }
        
        present(notificationCenter, animated: true, completion: nil)
    }
}

The Notification Center understands when it’s being presented modally and automatically includes a “Done” button in the top left corner so you do not have to worry about dismissing the Notification Center manually.

Presenting in a Tab Bar

Rover’s resolve mechanism doesn’t support Interface Builder so to add the Notification Center to a tab bar it must be done programmatically. The below example demonstrates how this can be done from within the viewDidLoad() method of a UITabBarController subclass.

class MyTabBarController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()

        // Resolve the Notification Center view controller
        guard let notificationCenter = Rover.shared?.resolve(UIViewController.self, name: "notificationCenter") else {
            return
        }
        
        // Set the notification center's `tabBarItem` which defines how its tab is displayed
        notificationCenter.tabBarItem = UITabBarItem(title: "Notifications", image: nil, tag: 0)

        // Add the Notification Center to the tab bar's list of view controller's
        self.viewControllers?.append(notificationCenter)
    }
}

Delivering Notifications

When authoring a campaign in the Rover Campaigns app, you have the option to enable “Notification Center” as one of the ways to deliver the campaign.

Alert Options

When Notification Center is enabled, the notification delivered by the campaign will be accessible in your app’s Notification Center in addition to the system-displayed push notification.

Notification Center Preview

Required Modules
  • RoverFoundation
  • RoverData
  • RoverUI
  • RoverNotifications