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]: BrazeDelegate methods are not called if app is not in memory #51

Closed Saulenco closed 1 year ago

Saulenco commented 1 year ago

Platform

iOS

Platform Version

iOS 16.1

Braze SDK Version

5.11.1

Xcode Version

14.2

Computer Processor

Apple (M1)

Repro Rate

100%

Steps To Reproduce

after braze is initialised:

 func start(in application: UIApplication, options: [UIApplication.LaunchOptionsKey: Any]?) {
        let brazeKey = URLHelper.brazeApiKey
        let endPoint = "sdk.iad-05.braze.com"
        let configuration = Braze.Configuration(
            apiKey: brazeKey,
            endpoint: endPoint
        )
        configuration.sessionTimeout = 60
        configuration.triggerMinimumTimeInterval = 1

        let braze = Braze(configuration: configuration)
        braze.delegate = self
        braze.inAppMessagePresenter = BrazeInAppMessageUI()
        BrazeService.braze = braze

        let center = UNUserNotificationCenter.current()
        center.setNotificationCategories(Braze.Notifications.categories)
    }

Expected Behavior

braze delegate method shouldOpenURL: should be called, like is called when push is receive when app in in foreground

Actual Incorrect Behavior

braze delegate method shouldOpenURL: should is not called called at first start .

Verbose Logs

No response

Additional Information

No response

jerielng commented 1 year ago

Hi @Saulenco - thanks for the reproduction steps! Sorry to hear you are not able to trigger a deeplink when the app isn't running.

To make sure I understand the scenario correctly, I wanted to verify that I'm following your same workflow:

For your in-app message, you're using this Deep Link Into App feature for your on-click behavior, correct? image

When you have the app closed, you are tapping the push notification on your phone's lock/home screen and expecting to deeplink into the desired location of your app, but that's not happening?

If the above is correct, I'm unable to reproduce the same issue from our end. Could you also provide more details on what the implementation of your braze(_:shouldOpenURL:) looks like?

Finally, since killing an app also cuts the connection to the Xcode debugger, are there any other visual cues or logging you can temporarily add to your braze(_:shouldOpenURL:) method to verify that it's not being called upon returning? This could help narrow down whether it's an issue with the method not being called or with the deeplink.

Saulenco commented 1 year ago

Hi @jerielng, yes we are using Deep Link Into App and we have a button on in app message that has a Deep Link Into App please see attached image: Screenshot 2023-03-15 at 09 12 55

and we have 2 scenarios: app is running, or it is in background:

app is killed, the app is not in Application stack

jerielng commented 1 year ago

Thanks for the additional info @Saulenco - unfortunately, we are still unable to reproduce this scenario.

Could you provide further details on your implementation? I notice you are using the following line: braze.delegate = self

Might it be possible that the reference to the BrazeDelegate that is being assigned in this start function may not be available at the time that your app is starting up and only after all the initialization is complete?

oriolpregona commented 1 year ago

Hi guys :) I believe this is duplicated from this ticket that was closed recently without getting fixed: https://github.com/braze-inc/braze-swift-sdk/issues/39

We are also experiencing the same issue, deeplinks are broken. The delegate is assigned, we do it all before didFinishLaunch, etc. Any update on this? Thanks!

Saulenco commented 1 year ago

so after more digging i have notice that we hold a strong reference to braze window like so:

let brazeWindow = UIApplication
            .shared
            .connectedScenes
            .flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
            .first { $0 is BrazeInAppMessageUI.Window }

and I have notice that if the app is from "cold start" this somehow disturbes the delegate, if i remove this, or use it as a getter without a strong reference it work as expected.

oriolpregona commented 1 year ago

I also have an update. Our url was escaped. This seems to work fine when simulating push notifications on the simulator, but not on real Braze usage. After removing the escaping, it works as expected ✅

jerielng commented 1 year ago

That's great to hear! It sounds like we have a solution in both cases, so I'll go ahead and close this issue, but feel free to reach back out if you have any further questions.