BatchInboxFetcher
@interface BatchInboxFetcher
BatchInboxFetcher allows you to fetch notifications that have been sent to a user (or installation, more on that later) in their raw form, allowing you to display them in a list, for example. This is also useful to display messages to users that disabled notifications.
Once you get your BatchInboxFetcher instance, you should call fetchNewNotifications: to fetch the initial page of messages: nothing is done automatically. This method is also useful to refresh the list.
In an effort to minimize network and memory usage, messages are fetched by page (batches of messages): this allows you to easily create an infinite list, loading more messages on demand. While you can configure the maximum number of messages you want in a page, the actual number of returned messages can differ, as the SDK may filter some of the messages returned by the server (such as duplicate notifications, etc…).
As BatchInboxFetcher caches answers from the server, instances of this class should be tied to the lifecycle of the UI consuming it. For example, you should keep a reference to this object during your UIViewController’s entire life. Another reason to keep the object around, is that you cannot mark a message as read with another BatchInbox instance that the one that gave you the message in the first place.
A BatchInboxFetcher instance will hold to all fetched messages: be careful of how long you’re keeping the instances around. You can also set a upper messages limit, after which BatchInbox will stop fetching new messages, even if you call fetchNextPage.
-
This class should not be instanciated directly: use BatchInbox to get a correctly initialized instance.
Declaration
Objective-C
- (nonnull instancetype)init;
-
Whether silent notifications should be filtered from the fetched notifications. This parameter should be set before the first fetch happens. If set to false, silent notifications (notifications not showing a visible message to the user) will not be filtered by the SDK.
For compatiblity, a notification content’s
body
property will be the empty string rather than nil. To differentiate silent notifications from visible ones, look at themessage
property: it will be nil if the notification is silent.Default: true
Declaration
Objective-C
@property (nonatomic) int filterSilentNotifications;
-
Number of notifications to fetch on each call, up to 100 messages per page. Note that the actual count of fetched messages might differ from the value you’ve set here.
Declaration
Objective-C
@property (nonatomic) int maxPageSize;
-
Maximum number of notifications to fetch. This allows you to let Batch manage the upper limit itself, so you can be sure not to use a crazy amount of memory. If you want to fetch unlimited messages, set this property to 0.
Default value: 200
Declaration
Objective-C
@property (nonatomic) int limit;
-
Returns whether all of the user or installation’s notifications have been fetched. If this property returns YES, calling fetchNextPage will always return an error, as there is nothing left to fetch. Also artificially returns YES if the maximum number of fetched messages has been reached.
Declaration
Objective-C
@property (readonly) int endReached;
-
Fetch new notifications. While fetchNextPage: is used to fetch older notifications than the ones currently loaded, this method checks for new notifications. For example, this is the method you would call on initial load, or on a “pull to refresh”. If new notifications are found, the previously fetched ones will be kept if possible, but might be cleared to ensure consistency.For example, if a gap were to happen because of a refresh, old notifications would be removed from the cache.
The completion handler is called on the main queue.
Declaration
Objective-C
- (void)fetchNewNotifications:(void (^_Nullable)(int *_Nullable, int))completionHandler;
Parameters
completionHandler
An optional completion handler can be executed on success or failure with either the fetched notifications or the detailed error.
-
Fetch a page of notifications. The completion handler is called on the main queue. Calling this method when no messages have been loaded will be equivalent to calling fetchNewNotifications:
Declaration
Objective-C
- (void)fetchNextPage:(void (^_Nullable)(int *_Nullable, int))completionHandler;
Parameters
completionHandler
An optional completion handler can be executed on success or failure with either the fetched notifications or the detailed error.
-
Mark a specific notification as read. The notification you provide will see its isUnread property updated.
If you call fetchNewNotifications: right away (or get a new BatchInboxFetcher instance), you might have notifications that you’ve marked as read come back to an unread state, since the server may have not processed the request yet.
Declaration
Objective-C
- (void)markNotificationAsRead: (nonnull BatchInboxNotificationContent *)notification;
Parameters
notification
The notification to be marked as read.
-
Marks all notifications as read.
Note that you will have to call allFetchedNotifications again to update the isUnread status of your copy of the notifications. If you call fetchNewNotifications: right away (or get a new BatchInboxFetcher instance), you might have notifications that you’ve marked as read come back to an unread state, since the server may have not processed the request yet.
Declaration
Objective-C
- (void)markAllNotificationsAsRead;
-
Mark a specific notification as deleted. The notification you provide will see its isUnread property updated.
If you call fetchNewNotifications: right away (or get a new BatchInboxFetcher instance), you might have notifications that you’ve marked as deleted come back, since the server may have not processed the request yet.
Declaration
Objective-C
- (void)markNotificationAsDeleted: (nonnull BatchInboxNotificationContent *)notification;