Swift SDK Inbox

This SDK is developed using the Swift programming language. Unlike our existing iOS SDK, we provide integration support with Swift Package Manager (SPM). You can take advantage of Swift's expressive and intuitive nature, enabling you to create sophisticated applications with ease.

Inbox Feature: Notification Handling

The Inbox feature within our platform manages push notifications in a manner designed to provide users with the most relevant and up-to-date information. One aspect of this functionality involves the handling of notifications sent within a specific time frame. Therefore, notifications sent five minutes ago and earlier will be deleted when a new notification is received. This ensures that only the latest and most pertinent information is retained in the user's inbox.

In your pod file, you should add NetmeraNotificationInbox and install to your app target like this;

pod "NetmeraNotificationInbox"

If your application needs information about the push notifications that are previously sent to device by Netmera, you can use NetmeraInbox class to fetch that information from Netmera.

The most common use case for this would be to show the list of notifications inside your application in an inbox-style interface.

NetmeraInbox is the core class providing methods and properties needed for operations on push notifications like fetching push objects or updating push objects' status, but you can not directly initialize a NetmeraInbox instance. You get an instance from SDK, then operate on that instance for future inbox actions. Here is the common workflow to use inbox feature of Netmera.

Determine properties of push notifications to fetch

You must first define filtering properties by creating a NetmeraInboxFilter instance. You determine which push notifications will be included in the fetched list by setting related properties of this NetmeraInboxFilter instance.

NetmeraInboxFilter class provides filtering according to the following options:

  • Inbox Status: Read / Unread / Deleted

  • Categories: Categories to which push notifications are belong.

  • Including expired push notifications or not.

  • Page Size: This is not to filter, but to determine the size of chunks which will be gathered during one request.

// 1. Define inbox manager
var  inboxManager: NetmeraInboxManager?
// 2. Create filter for fetching inbox
let filter = NetmeraInboxFilter(status: status,
								pageSize: 10,
								shouldIncludeExpiredObjects: true,
								categories: ["category_names"] //Optional
// 3. Crete inbox manager instance
self.inboxManager = Netmera.inboxManager(with: filter)

Fetch the first page and get the NetmeraInbox instance

Now, you can request from Netmera to return the list of push notification objects matching with the filter object using the following code:

inboxManager?.inbox(callback: { result in
	// List inbox

Update the status of push notifications

Push notifications may have 3 different states, which are the following:

  • Unread

  • Read

  • Deleted

These three states allows you to implement a simple notification inbox interface for your users where they can read messages, mark previously read message as unread, delete messages and restore them again if needed.

You can make transitions among states for push notifications inside inbox using -updateStatus:forPushObjects:completion: method. Calling this method will start an asynchronous request to update status for given push objects, and given completion block will be called upon the result of the request.

Here is a sample implementation which deleted the first 5 push objects from inbox:

// To update status of given push objects
inboxManager?.updateStatus(status, for: [object]) { result in
	// List inbox

// To update status of all push objects
inboxManager?.updateStatusForAllPushObjects(status) { result in
	// List inbox

Fetch more pages

If you set a custom pageSize value as a filtering option, result of the first fetch operation may not contain all push objects which matches with the given filtering criteria. In this case, you can fetch next chunk of objects using the following code:

inboxManager?.nextPage(callback: { result in
	// List inbox

NetmeraInbox instance returned as the result of -fetchInboxUsingFilter:completion: method stores the fetched list of objects incrementally. Specifically, inbox.objects property will include all list of objects fetched until that time. For instance, if you set pageSize as 10, and fetch 3 pages in total (one with -fetchInboxUsingFilter:completion:, two with -fetchNextPageWithCompletionBlock:), inbox.objects array will contain all 30 objects in these 3 pages. Therefore, you can solely rely on this array while showing push notifications to your users inside a table view or collection view.

If operation fails for some reason, completion block will be called with a nonnull error parameter describing the reasons of failure.

If you call this method when there is no more page left, method immediately calls completion block with an appropriate error.

ℹ️ You can check if you have fetched all pages via hasNextPage property of NetmeraInbox instance. It will have value NO when all pages have been fetched.

Get count of push notifications according to status

You can show your users information about total count of push notifications according to inbox status using -countForStatus: method like this:

self.inboxManager?.count(for: NetmeraInboxStatus.read)

Last updated