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]: Intermittent crash in BrazeInAppMessageUI's dismiss method #135

Closed vicsuccess closed 2 months ago

vicsuccess commented 3 months ago

Platform

iOS

Platform Version

iOS 17.4.1

Braze SDK Version

8.4.0

Xcode Version

Xcode 15.3

Computer Processor

Apple (M1)

Repro Rate

1%

Steps To Reproduce

  1. When entering a specific UIViewController and viewDidAppear is called, dismiss the BrazeInAppMessageUI.
  2. Crashes occur very intermittently.

Expected Behavior

BrazeInAppMessageUI dismisses correctly.

Actual Incorrect Behavior

In the BrazeInAppMessageUI's func dismiss(completion: (() -> Void)? = nil), intermittent crashes occur due to force unwrapping of the following items at the time when presented is set in didSet

Resolve intermittent crashes by making the variables optional.

BrazeInAppMessageUI.swift

open var innerYConstraint: NSLayoutConstraint!
open var outerYConstraint: NSLayoutConstraint!
var maxWidthConstraints: [NSLayoutConstraint]!
var minHeightConstraint: NSLayoutConstraint!

Verbose Logs

Please refer to the Xcode console log

BrazeUI/InAppMessageUISlideupView.swift:418: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

스크린샷 2024-08-02 오전 1 21 27

BrazeInAppMessageUI

스크린샷 2024-08-02 오전 2 23 44

Additional Information

No response

jerielng commented 3 months ago

Hi @vicsuccess, thanks for raising this. It seems that there is some kind of race condition occurring here where the constraints are not allocated for some reason at the time of dismissal. We've tried to safeguard around this by adding an error handling scenario.

Could you share further details on how you are presenting the IAM? I see that you have implemented a dismiss function. If you can provide some kind of project that reproduces this error to our support team support@braze.com, that would be helpful. Thank you!

vicsuccess commented 3 months ago

HI @jerielng

When the app is sent to the background while Screen A is displayed, an IAM message is sent from the Braze development console, and then Screen A is brought to the foreground and transitions to Screen B, dismissing in viewDidAppear, repeating this scenario causes a crash at the point of dismissing while entering Screen B.

We are operating a large-scale service, so your assistance in resolving this issue is greatly appreciated. Please leave additional comments if necessary. (I hope to proceed with communication through this thread.)

jerielng commented 3 months ago

Hey @vicsuccess, do you happen to have any sample code you can share that easily reproduces the issue? Or any verbose logs that show the order and history of the view presentation? We would also like to understand if this is occurring only on slide-up in-app messages, or for other message types - if you have any campaigns that you can share, this would be helpful and speed up the debugging process. Since campaign links are unique to your user account, we recommend sending these to our support email rather than sharing them on a public thread.

When you mention repeating this scenario causes a crash at the point of dismissing while entering Screen B., do you mean that this always happens on a second attempt at dismissing the screen?

We are open to the idea of making these values optional rather than force-unwrapping but would like to understand the error scenario more deeply to prevent it from manifesting in a different way that is more difficult to debug (i.e. the view dimensions not displaying correctly or causing an issue or crash elsewhere).

vicsuccess commented 3 months ago

Hi @jerielng Sorry for the delay in replying due to work. I will leave a comment as soon as possible.

vicsuccess commented 2 months ago

@jerielng I apologize for the delay in further communication. I have sent an email that includes more detailed information, including the steps to reproduce the crash situation. I appreciate your assistance with this matter.

Thank you.

lowip commented 2 months ago

Hi @vicsuccess,

We have released the Swift SDK 10.3.0 which resolves this issue.

Best,