Appboy / appboy-ios-sdk

Public repo for the Braze iOS SDK
https://www.braze.com
Other
165 stars 142 forks source link

InAppMessages KeyWindow #314

Closed SgSarm closed 2 years ago

SgSarm commented 2 years ago

Report

Describe your environment.


Info Value
Platform Name iOS
Platform Version > 10.3+
SDK Version 4.33.0
Integration Method Cocoapods
Xcode Version Xcode 13.0
Computer Processor Intel-based
Repro rate All the time (100%)

What did you do?

Implement BRAZE-SDK following the tutorial and try to open deeplinks from InAppMessages.

What did you expect to happen?

If I send an InAppMessage with Button and a Deeplink I would like to get redirected to the page according to the Deeplink.

What happened instead?

InAppMessage sets rootViewController -> we don't get redirected to the target ViewController.

Steps to reproduce

In our Deeplink Handling we need the rootViewController. Since before an InAppMessage is displayed, displayInAppMessageViewWithAnimation in ABKInAppMessageWindowController gets called an the rootViewController is set to self.inAppMessageWindow.rootViewController = self; (Line 304) we don't have that Information anymore because the InAppMessage is the new rootViewController and we're not getting deeplinked.

Do you have any ideas how we can solve this problem?

Are you doing any feature customizations that may relate to the issue? Can you share the code snippet?

No Customizations should related to that. We change Fonts and CornerRadius.

Project that demonstrates the issue

Dont have one.

Thanks in advance

Bucimis commented 2 years ago

@SgSarm Would it be possible, as a workaround, for you to synchronously close the in-app message UI using hideCurrentInAppMessage before handling the deep link?

lowip commented 2 years ago

Hi @SgSarm

Could you provide your deeplink handling code? (if sensitive you can send it directly at support@braze.com, referencing this github issue in the email)

I am not sure I understand what you mean by:

In our Deeplink Handling we need the rootViewController.

Braze's in-app message are displayed on top of your application window in an additional UIWindow with its own rootViewController. The inAppMessageWindow.rootViewController is never your application root view controller.

SgSarm commented 2 years ago

Before i forget to mention, we're using DeeplinkKit.

@Bucimis right now, as a workaround we're getting it by UIApplication.shared.windows.first?.rootViewController which initilly was UIApplication.shared.keyWindow?.rootViewController

@lowip sure, I can provide some:

override func presentTargetViewController(_ targetViewController: (UIViewController & DPLTargetViewController)!, in presentingViewController: UIViewController!) {
        let rootViewController = UIApplication.shared.keyWindow?.rootViewController // Is Always ABKInAppMessageWindowController when hitting Button with Deeplink from inAppMessage
        guard let tabBarController = rootViewController?.presentedViewController as? UITabBarController
        else {  return } 

        NotificationCenter.default.post(name: ABCNotifications.cancelPlayback.name, object: self)

        tabBarController.selectedIndex = tabBarController.indexOf(rootViewController: DEFViewController.self) ?? 0
        let navigationController = tabBarController.selectedViewController as? UINavigationController

        if let abcViewController = targetViewController as? ABCViewController {
            navigationController?.popToRootViewController(animated: false)
            navigationController?.pushViewController(abcViewController, animated: true)
        }
}
hokstuff commented 2 years ago

Hi @SgSarm,

I'm just checking in about this issue. Since your integration is more particular and involves other Deeplink dependencies, it would be best to email support@braze.com if you run into more issues so we can take a more in-depth look.

Due to inactivity and what appears to be a workaround for your situation, I will close out this issue. Feel free to comment or contact Support if you believe this was done in error - thank you!