braze-inc / braze-swift-sdk

Braze SDK for the Apple ecosystem, including: iOS, macOS, iPadOS, visionOS, tvOS
https://www.braze.com
Other
52 stars 19 forks source link

[Bug]: `BrazeInAppMessageUI.presentNext()` skips `BrazeInAppMessageUIDelegate.displayChoice(for:)` #71

Closed remarcus closed 1 year ago

remarcus commented 1 year ago

Platform

iOS

Platform Version

16.5.1

Braze SDK Version

6.3.1

Xcode Version

14.3.1

Computer Processor

Apple (M1)

Repro Rate

100%

Steps To Reproduce

Example:

  1. Implement BrazeInAppMessageUIDelegate containing displayChoice(for:)
  2. Assign delegate to the BrazeInAppMessageUI presenter
  3. Launch In App Message campaign with Session Start trigger
  4. Launch the app
  5. Return .later display choice for In App Message
  6. In App message is placed to the top of the stack
  7. Trigger presentNext() on the presenter

Expected Behavior

displayChoice(for:) is invoked and decision can be made about the given campaign

Actual Incorrect Behavior

inAppMessage(_ ui:, willPresent:, view:) is invoked

Verbose Logs

No response

Additional Information

We want to control the In App Message display logic and we used to do that with Appboy.sharedInstance()!.inAppMessageController.displayNextInAppMessage(). This method used to repeat going through the display choice flow.

My question is this a bug or a custom implementation of BrazeInAppMessagePresenter should be considered.

For HTML and Control campaigns we use Braze UI to handle the message, for other type of campaigns we display them by using our own UI library. So we have to have availability to both.

lowip commented 1 year ago

Hi @remarcus,

Thank you for opening this issue. The method presentNext() currently work as intended and does not call the delegate. We'll update the documentation accordingly.

To achieve the desired behavior, you can do something like:

if let message = inAppMessageUI.stack.last {
  // Call the default presenter protocol method 
  //  → executes the `inAppMessage(_:displayChoiceForMessage:)` delegate method
  inAppMessageUI.present(message: message)
}

The message is automatically removed from the stack when presented.

Let us know if that works for you.

remarcus commented 1 year ago

Thanks @lowip,

It seems to work great now. I will close the issue, if we will find something during testing I will update the issue.

Have a great day!