Initialization

To initialize the SDK you have to add MBMessagesSwift to the array of plugins of MBurger.

import MBurgerSwift
import MBMessagesSwift

...

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    MBManager.shared.apiToken = "YOUR_API_TOKEN"
    MBManager.shared.plugins = [MBMessages()]

    return true
}

Then you have to tell MBManager.shared that the app has been opened with MBManager.shared.applicationDidFinishLaunchingWithOptions(launchOptions: launchOptions), this will trigger all the startup actions of the MBurger plugins. Once you've done this in app messages will be fetched automatically at the startup of the application and showed, if they need to be showed.

...

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    MBManager.shared.apiToken = "YOUR_API_TOKEN"
    MBManager.shared.plugins = [MBMessages()]

    MBManager.shared.applicationDidFinishLaunchingWithOptions(launchOptions: launchOptions)

    return true
}

Initialize MBMessages with parameters

You can set a couples of parameters when initializing the MBMessages plugin:

let messagesPlugin = MBMessages(delegate: [the delegate],
                                viewDelegate: [view delegate],
                                styleDelegate: [style delegate],
                                messagesDelay: 1
                                debug: true)
  • messagesDelay: it's the time after which the messages will be displayed once fetched

  • debug: if this is set to true, all the message returned by the server will be displayed, if this is set to false a message will appear only once for app installation. This is false by default

  • delegate: the delegate will receive a call if the fetch of the messages fails, with the error that caused the fail, see MBMessagesDelegate for more details.

  • viewDelegate: the view delegates will receive calls when views of messages are showed or hidden, it will also receives a call when the button of the views will be touched, so you need to implement this protocol if you want to open an in-app link from an in app message. See MBInAppMessageViewDelegate for a detailed description of the protocol.

  • styleDelegate: you can use this protocol to specify colors and fonts of the in app messages. See Stylize in app messages for more details

Automation

If messages have automation enabled they will be ignored and managed by the MBAutomationSwift SDK so make sure to include and configure the automation SDK correctly.

Last updated