Skip to content

Advanced Notification History

Basic example

With these few lines of code:

let historyVC = NITNotificationHistoryViewController()
historyVC.show()
NITNotificationHistoryViewController *historyVC = [[NITNotificationHistoryViewController alloc] init];
[historyVC show];

you are able to show the user notification history, ordered by recieving date, latest on top.

Inbox list

Optionally, you can display the content in your UINavigationController:

historyVC.show(navigationController: yourNavigationController!, /*optional*/ title: "my coupons")
[historyVC showWithNavigationController:yourNavigationController];
// or
[historyVC showWithNavigationController:yourNavigationController title:@"my notifications"];

By default content of type "Custom JSON" is not included in the list.

Advanced examples

Include/exclude content types

The notification history can include all type of content, but you can configure inclusion for the following 3 types: custom jsons, feedback requests and coupons.

By default our UI excludes custom jsons, and includes feedback requests and coupons.

You can set which of those 3 types to include, by setting these three fields:

historyVC.includeCoupons = false
historyVC.includeFeedbacks = false
historyVC.includeCustomJson = true
historyVC.show()
historyVC.includeCoupons = FALSE;
historyVC.includeFeedbacks = TRUE;
historyVC.includeCustomJson = TRUE;
[historyVC show];

Custom behaviour

You can set a custom view for when the notification history is empty by setting the noContentView field:

let view = UIView()
view.backgroundColor = UIColor.blue
historyVC.noContentView = view
historyVC.noContentView = myNoContentView;

You can enable the behavior of tapped links on content detail with the attribute:

historyVC.openLinksInWebView = true;
historyVC.openLinksInWebView = @YES;

The default value is false.

Manually handle notification history

You can get the notification history directly from the SDK and decide what to do with it:

To get the list, call:

NearManager.shared.notificationHistory { (items, error) in
    if let error = error {
        NSLog("Notification history error: %@", error.localizedDescription)
    }

    if let items = items {
        // handle the notification list
    }
}
[manager historyWithCompletion:^(NSArray<NITHistoryItem *> * _Nullable items, NSError * _Nullable error) {
    if (error != nil) {
        // error
    } else {
        // handle the notification list
    } 
}];

An HistoryItem object has these fields:

  • reactionBundle : the NITReactionBundle instance of the Near content delivered by that notification.
  • read : a Bool representing whether the notification was ever read or not by the user
  • trackingInfo : the NITTrackingInfo instance for that notification. Useful for tracking (see below).
  • timestamp : an NSTimeInterval instance for the epoch timestamp of the notification. You can use the date method to get a NSDate object.
  • isNew : a Bool representing whether the notification is new for the user. Its value is the same as read, unless you use markNotificationHistoryAsOld to mark all previous notifications as old. See the Updates chapter to learn more.

Warning: if you are implementing the list yourself, remember to track the items as opened when the user taps on them. See the trackings section to learn how to track a notification as opened.

Updates

To get notified on updates for history notifications, you can set the notificationDelegate

NearManager.shared.notificationDelegate = self
...
extension MyClass: NearManagerNotificationDelegate {
    func manager(_ manager: NearManager, updatedHistoryWith items: [NITHistoryItem]?) {
        let count = items?.filter { $0.isNew }.count ?? 0
    }
}
NITManager.defaultManager.notificationDelegate = self;
...
- (void)historyUpdatedWithItems:(NSArray<NITHistoryItem *> * _Nullable)items {
    int unreadCount = 0;
    for(NITHistoryItem *item in items) {
        if(item.isNew) { unreadCount++; }
    }
}

If you want to update a badge you should use the isNew field to count new notifications. By default, this field will be the same as read, so any tracking regarding the item can change its value. If you want to manually set all the notification as acknowledged (meaning that isNew will be false), without loosing the read information or tracking every single notification interaction, you can call this method:

NearItManager.getInstance().markNotificationHistoryAsOld();
[NITManager.defaultManager markNotificationHistoryAsOld];