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]: OpenURL is not called after handling Push with deeplink #62

Closed suhabaobaid closed 1 year ago

suhabaobaid commented 1 year ago

Platform

iOS

Platform Version

IOS 16.0.3

Braze SDK Version

6.1.0

Xcode Version

Xcode 14.2

Computer Processor

Apple (M1)

Repro Rate

100%

Steps To Reproduce

Example:

  1. Send a test Push with Deep Link into application option and provide link
  2. Click on the push notificaiton on the device
  3. didReceiveRemoteNotification is called, then call braze.notifications.handleBackgroundNotification(userInfo: userInfo, fetchCompletionHandler: completionHandler)
  4. Expect application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) to be called due the url but it is not called so the deeplink url is not processed as expected

Expected Behavior

openURL gets called with the URL specified in the push.

Note: We just migrated to the Braze sdk 6.1.0 and prior to that was using Appboy sdk and it was working as expected.

Actual Incorrect Behavior

no deeplink is being processed, push only opens the app

Verbose Logs

No response

Additional Information

In-app deeplinking works as expected as well as email deeplinks

jerielng commented 1 year ago

Hey @suhabaobaid , thanks for the reproduction steps! We'll take a closer look and keep you updated.

For more details, do you notice if this is reproducible at any point when tapping a push notification, or does this only happen under certain app states (i.e. app is not in memory, app is open but in background)?

Additionally, to double check, do you happen to have any custom implementations of braze.delegate other than the default, particularly with the shouldOpenURL method?

Could you also verify how the URL scheme is registered in your Info.plist?

suhabaobaid commented 1 year ago

hey @jerielng Thanks for checking on it!

For more details, do you notice if this is reproducible at any point when tapping a push notification, or does this only happen under certain app states (i.e. app is not in memory, app is open but in background)?

It doesn't work when tapping the notification both if app is in background and if not in memory

Additionally, to double check, do you happen to have any custom implementations of braze.delegate other than the default, particularly with the shouldOpenURL method?

No custom implementations for the braze.delegate

Could you also verify how the URL scheme is registered in your Info.plist?

Yeah, it is the same as the documentation as well as the same scheme that was used when we were using the Appboy sdk and it was working fine

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>YOUR.SCHEME</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>YOUR.SCHEME</string>
        </array>
    </dict>
</array>
suhabaobaid commented 1 year ago

If it is any help as well, calling UIApplication.shared.canOpenURL in the app with the URL sent through the Push notification returns true. So it is not a scheme issue?

jerielng commented 1 year ago

If it is any help as well, calling UIApplication.shared.canOpenURL in the app with the URL sent through the Push notification returns true. So it is not a scheme issue?

Thanks! That's good info to know. For a sanity check, one thing you can also try is implementing the braze.delegate and shouldOpenURL method and then checking if that delegate method is being called in your case. You should be able to verify whether it's being triggered in 1) your in-app deeplink case, which works as expected and 2) the push notification deeplink case

So for instance, using a sample class as the BrazeDelegate:

class TestDelegate: BrazeDelegate {
  func braze(_ braze: Braze, shouldOpenURL context: Braze.URLContext) -> Bool {
    return true // Set a breakpoint here
  }
}

and then on your braze instance, assigning the delegate at app launch:

braze.delegate = TestDelegate()

Additionally, if there are any logs you can also provide, those would be helpful as well!

suhabaobaid commented 1 year ago

Just tested that out, for 1) in-app: shouldOpenURL is triggered, 2) push: shouldOpenURL is not triggered.

Is there any specific logs that would help? Other than the ones provided

jerielng commented 1 year ago

It's also possible that the notification processing may not be fully handled. You noted that braze.notifications.handleBackgroundNotification is being called when didReceiveRemoteNotification is triggered. Upon tapping the push notification, userNotificationCenter(_:didReceive:withCompletionHandler:) should also execute, which is where you should be handling the URL from the payload.

Referring to this section here, could you verify that braze.notifications.handleUserNotification is also being triggered from this UNUserNotificationCenterDelegate method?

We have some examples in our public repo to show what this may look like.

suhabaobaid commented 1 year ago

ah yes! implementing userNotificationCenter(_:didReceive:withCompletionHandler:) did the trick. It is now working as expected.

Although in the migration doc, it wasn't clear that this was a needed step to handle processing the standard notification properly and more so if we need to handle the custom actions of the push notification

Thanks for the assist!