Firebase In-app messaging button action doesn't work

4.2k Views Asked by At

In my iOS project, I have setup all the dependencies for firebase in-app messaging and on the button click I need to take the user to a webpage.

The banner and the message is getting received in the device as required, but the button action doesn't open the web page.

Please note that the same work for android app without any issue, it opens the url in the browser without any issue.

I'm sending the URL in the correct format ie : https://www.something.com

Please anyone can show some light on this?

3

There are 3 best solutions below

3
On BEST ANSWER

Okay,the solution is to use firebase dynamic links and add a method in AppDelegate.swift

func application(_ application: UIApplication,
               open url: URL,
               sourceApplication: String?,
               annotation: Any) -> Bool {
let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url)

if dynamicLink != nil {
  if dynamicLink?.url != nil {
    // Handle the deep link. For example, show the deep-linked content,
    // apply a promotional offer to the user's account or show customized onboarding view.
    // ...
  } else {
    // Dynamic link has empty deep link. This situation will happens if
    // Firebase Dynamic Links iOS SDK tried to retrieve pending dynamic link,
    // but pending link is not available for this device/App combination.
    // At this point you may display default onboarding view.
  }
  return true
}
return false
}

check more in in-app messaging sample from google

6
On

I had this problem ever since In-App Messaging Launched. I do android part without any problem but for iOS, i cannot get the button work. Thank to the insight from this post. But the above addition alone to the AppDelegate do not work. I have to add more:

func application(_ application: UIApplication,
                 open url: URL,
                 sourceApplication: String?,
                 annotation: Any) -> Bool {
    let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url)

    if dynamicLink != nil {
        if dynamicLink?.url != nil {
            // Handle the deep link. For example, show the deep-linked content,
            // apply a promotional offer to the user's account or show customized onboarding view.
            // ...
        } else {
            // Dynamic link has empty deep link. This situation will happens if
            // Firebase Dynamic Links iOS SDK tried to retrieve pending dynamic link,
            // but pending link is not available for this device/App combination.
            // At this point you may display default onboarding view.
        }
        return true
    }
    return false
}



func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
        // ...
    }

    return handled

}
1
On

Make sure your AppDeletegate’s application:openURL:sourceApplication:annotation: (iOS 8 and older) and application:openURL:options: (iOS 9 and up) returns YES/true or NO/false correctly. In-App Messaging SDK would check the return value from these methods to decide if they are already handled by the app or not.

So for web link case, make sure you return No/false so that In-App Messaging SDK could forward it the system to be loaded in browser. You can debug this behavior by checking how your appdelegate' url handling method is being triggered after the button is clicked.