Skip to content

Commit

Permalink
Add IAM handlers documentation (#499)
Browse files Browse the repository at this point in the history
* Add documentation

* Add delayIndefinitely option
  • Loading branch information
nzagorchev authored Jul 8, 2022
1 parent dd0ad4c commit 4eea684
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@
import Foundation
import UIKit


extension ActionManager {
/// Configuration of the `ActionManager`
/// - Precondition: set a new `Configuration` to the `ActionManager` with the defined options
public class Configuration {

/// Keep or dismiss in-app message when push notification is opened. If kept, the action from the
/// push notification will go into the queue and will be presented after in-app dismissal, otherwise
/// the in-app is dismissed and the push notification's action is presented.
///
/// - Default value: `true`
public let dismissOnPushArrival: Bool

/// Message queue is paused when app is backgrounded and resumed when app is foregrounded
/// Set to `false` to prevent resuming the message queue when app enters foreground
///
/// - Default value: `true`
public let resumeOnEnterForeground: Bool

public init(dismissOnPushArrival: Bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extension ActionManager {
}
}

/// Triggers all postponed messages when indefinite time was used with `MessageDisplayChoice`
@objc public func triggerDelayedMessages() {
appendActions(actions: delayedQueue.popAll())
}
Expand All @@ -59,6 +60,7 @@ extension ActionManager {
enum MessageDisplay {
case show
case discard
/// Delay with seconds: 0 to delay indefinitely
case delay(seconds: Int)
}

Expand All @@ -77,6 +79,11 @@ extension ActionManager {
.init(decision: .delay(seconds: seconds))
}

/// Delays the action indefinitely - until `triggerDelayedMessages` is called
@objc public static func delayIndefinitely() -> Self {
.init(decision: .delay(seconds: 0))
}

required init(decision: MessageDisplay) {
super.init()
self.decision = decision
Expand Down
22 changes: 22 additions & 0 deletions LeanplumSDK/LeanplumSDK/ClassesSwift/Actions/ActionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Foundation
@objcMembers public class ActionManager: NSObject {
public static let shared: ActionManager = .init()

/// `ActionManager.Configuration` of the `ActionManager`
/// Set a new configuration to override a configuration option
public var configuration: Configuration = .default

lazy var queue: Queue = Queue()
Expand All @@ -23,11 +25,15 @@ import Foundation
public var messagesDataFromServer: [AnyHashable: Any] = [:]
public var actionDefinitionsFromServer: [AnyHashable: Any] = [:]

/// When disabled, it stops executing actions and new actions will not be added to the queue.
public var isEnabled: Bool = true {
didSet {
Log.info("[ActionManager] isEnabled: \(isEnabled)")
}
}

/// When paused, it stops executing actions but new actions will continue to be added to the queue
/// Value will be changed to `false` when app is in background and to `true` when app enters foreground
public var isPaused: Bool = false {
didSet {
if isPaused == false {
Expand Down Expand Up @@ -63,26 +69,42 @@ import Foundation
}

var shouldDisplayMessage: ((ActionContext) -> MessageDisplayChoice)?
/// Called per message to decide whether to show, discard or delay it.
/// - Note: to delay a message indefinitely, use delay with value -1
@objc public func shouldDisplayMessage(_ callback: @escaping (ActionContext) -> MessageDisplayChoice) {
shouldDisplayMessage = callback
}

var onMessageDisplayed: ((ActionContext) -> Void)?
/// Called when the message is displayed.
@objc public func onMessageDisplayed(_ callback: @escaping (ActionContext) -> Void) {
onMessageDisplayed = callback
}

var onMessageDismissed: ((ActionContext) -> Void)?
/// Called when the message is dismissed.
@objc public func onMessageDismissed(_ callback: @escaping (ActionContext) -> Void) {
onMessageDismissed = callback
}

var onMessageAction: ((_ actionName: String, _ context: ActionContext) -> Void)?
/// Called when a message action is executed.
@objc public func onMessageAction(_ callback: @escaping (_ actionName: String, _ context: ActionContext) -> Void) {
onMessageAction = callback
}

var prioritizeMessages: ((_ contexts: [ActionContext], _ trigger: ActionsTrigger?) -> [ActionContext])?
/// Called when there are multiple messages to be displayed. Messages are ordered by Priority.
/// Messages can be reordered or removed if desired. Removed messages will not be presented.
/// Messages will be presented one after another in the order returned.
///
/// - Note: If this function is not implemented, the first message is presented only.
///
/// - Parameters:
/// - contexts: messages' contexts
/// - trigger: the action trigger that triggered the messages
///
/// - Returns: the messages that should be presented in that order
@objc public func prioritizeMessages(_ callback: @escaping (_ contexts: [ActionContext], _ trigger: ActionsTrigger?) -> [ActionContext]) {
prioritizeMessages = callback
}
Expand Down

0 comments on commit 4eea684

Please sign in to comment.