Skip to content

Message storage

Davor Komušanac edited this page Dec 7, 2022 · 2 revisions

Mobile Messaging SDK for Flutter supports a message storage feature. If the storage is enabled in configuration, then the plugin will save all push messages to the configured message storage. Plugin will handle and save messages that are received both during background and during foreground operation of the app. Two types of message storage configuration are supported: default storage and an external one.

Default message storage

Mobile Messaging SDK supports a built-in message storage. defaultMessageStorage option shall be set to true in initialization configuration to enable it. If default message storage is enabled, then it will be possible to access all the messages received by the library using methods described below.

    await InfobipMobilemessaging.init(Configuration(
        applicationCode: "Your Application Code",
        androidSettings: AndroidSettings(
          firebaseOptions: FirebaseOptions(
              apiKey: "Some-API-Key",
              applicationId: "1:1234567890:android:abc123",
              projectId: "project-123ab"
          ),
        ),
        defaultMessageStorage: true,
    ));
...

/**
 * Retrieves all messages from message storage
 */
List<Message> messages = await InfobipMobilemessaging.defaultMessageStorage().findAll();

//**
 * Retrieves message from the storage using provided message id
 */
Message message = await InfobipMobilemessaging.defaultMessageStorage().find(messageId);

/**
 * Deletes all messages
 */
await InfobipMobilemessaging.defaultMessageStorage().deleteAll();

/**
 * Deletes a messaging with the provided message id
 */
await InfobipMobilemessaging.defaultMessageStorage().delete(messageId);

Notice

Default message storage is a simple wrapper implementation over Core Data on iOS and SQLite on Android and is currently not designed to support large numbers of received messages. Note that performance of default message storage may decrease with the increasing number of messages stored inside.

Clone this wiki locally