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]: Push Notification links issue when app is closed #73

Closed remarcus closed 1 year ago

remarcus commented 1 year ago

Platform

iOS

Platform Version

16.6

Braze SDK Version

6.5.0

Xcode Version

14.3.1

Computer Processor

Apple (M1)

Repro Rate

100%

Steps To Reproduce

Hey!

This is probably not a bug, still maybe you will be able to assist me with this.

  1. We have a manual implementation for Push Notifications / Push Stories.
  2. When app is fully closed we send a Push Notification containing Deep Link or Web URL click action for the notification body.
  3. User clicks on the Push Notification.

Expected Behavior

App is opened and URL is handled.

Actual Incorrect Behavior

App is opened and no further actions completed.

Verbose Logs

No response

Additional Information

Deep Link / Web URL is handled if app is in foreground or background. Open and Delivery tracked if app is in foreground, background. Open and Influenced tracked if app is fully closed.

So my guess is that Braze SDK is not active when Push Notification is being handled, it used to work with similar setup when using Appboy SDK.

Maybe you have some ideas how I could troubleshoot it?

jerielng commented 1 year ago

Hey @remarcus, are you unable to process notification links when the app is backgrounded, or only when it's fully closed? If it only occurs when it's fully closed, it may be how you are initializing and maintaining your reference to the Braze instance. In such a case, would you mind sharing any code snippets containing how you are setting up the SDK?

There are a couple of other things you can check:

  1. Can you verify that you have the Background Modes entitlement added to your Xcode project with Remote notifications selected?
  2. In the integration tutorial, can you verify that you've done the necessary steps to handle background notifications? This should be step 5 in the manual option:
    func application(
    _ application: UIApplication,
    didReceiveRemoteNotification userInfo: [AnyHashable : Any],
    fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
    ) {
    if let braze = AppDelegate.braze, braze.notifications.handleBackgroundNotification(
      userInfo: userInfo,
      fetchCompletionHandler: completionHandler
    ) {
      return
    }
    completionHandler(.noData)
    }

There are some threads from the past that you can also reference to see if you are observing similar issues and how they were resolved:

remarcus commented 1 year ago

Hey @jerielng, Thanks for a quick response!

Only when the app is fully closed.

We're migrating from Appboy so general setup didn't change like entitlements or profiles.

While doing more testing on current setup in Appboy it seems that it tracks both Direct and Influenced opens for a singular campaign, so it seems that SDK was initially also initialised too late, but due to it being a singleton it might have worked out in the end.

The only real problem we have is with fully closed application.

For now I will close this issue as I have to do some more digging on our side. Thanks!

lucasGabrielDeAA commented 1 year ago

Is there any updates for this issue? I am facing the same behavior in my iOS app, the only difference is that I am using the 7.0.0 version of the react-native SDK, with automatic integration for push-notifications and I followed all the setup for push-story. And it only happens when the app is killed and receives a push-story with a deep-linking. If the app receives a push-notification with deep-link it works in every app state(foreground, background, killed)

jerielng commented 1 year ago

Hey @lucasGabrielDeAA, could you double check if you have set up an App Group in Xcode per step 4 in the push stories tutorial? If it still persists, could you share some additional reproduction steps and verbose logs, along with any relevant integration details with our support team at support@braze.com

lucasGabrielDeAA commented 1 year ago

Hi @jerielng ! Yes, I did, the push-story is working fine for many other cases. I already submitted a ticket for this on Braze support, just wanted to check if someone else would to be facing the same issue and found a solution. Thanks for you support

remarcus commented 9 months ago

Hey, missed the comments, we managed to fix this as we used to start SDK when user session would become available and this happens too late for Push handling to work properly.

I didn't want to raise additional issue, still this is somewhat related. If a deeplink is used in campaigns Braze forwards it to application(_:open:options:), still if Web url is used it seems that Braze has a built in Web View and link is not forwarded back to the app.

If we would like to control this, would it be a proper way to return false in BrazeDelegate shouldOpenURL and handle the url opening ourselves as we have our own Web View implementation and would like to use that instead. Would it not affect tracking? Thanks.

hokstuff commented 9 months ago

Hi @remarcus,

It sounds to me that there are a few different parts to your situation. I've responded inline below with my understanding and any follow up questions. Please respond on a different thread directly to support@braze.com with the answers so we can talk there instead of on this existing thread. Thank you!


we managed to fix this as we used to start SDK when user session would become available and this happens too late for Push handling to work properly

It sounds like you used to delay initialization of Braze until after the app has been launched and that caused Push not to work properly. After initializing Braze immediately after launch, this causes Push to work again.

If a deeplink is used in campaigns Braze forwards it to application(_:open:options:), still if Web url is used it seems that Braze has a built in Web View and link is not forwarded back to the app.

If we would like to control this, would it be a proper way to return false in BrazeDelegate shouldOpenURL and handle the url opening ourselves as we have our own Web View implementation and would like to use that instead. Would it not affect tracking? Thanks.

Is your question referencing a Push opening a deeplink into a certain part of your app, or are you referencing a Push opening a separate web page (e.g. https://www.braze.com/)?

The Push tracking events (e.g. Push received, push open) will occur automatically, regardless if you return true or false in BrazeDelegate shouldOpenURL (see docs for more details). However, if you wish to perform your own actions after selecting the push, such as opening your custom webview, you should return false in BrazeDelegate shouldOpenURL and then implement your own code. You should also verify that the behavior around the metrics are as expected, because that will depend on your actual code customization.

Thanks, Daniel