Branch does not open the App Store link

☆樱花仙子☆ 提交于 2019-12-25 18:26:27

问题


I use Branch to create deep links. I added a new control parameter ios_has_app_url and ios_url. Clicking on the deep link when the application is installed then everything works correctly, but if you click on the deep link when the application is not installed on the device then during startup, I see that the browser instead of opening ios_url (App Store link), it tries to open ios_has_app_url. How can I fix it?

private func createDeepLink(_ card: CardModel) -> (branchUniversalObject: BranchUniversalObject, branchLinkProperties: BranchLinkProperties) {
    let branchUniversalObject = BranchUniversalObject(canonicalIdentifier: ("cardId/\(card.id)"))
    branchUniversalObject.title = card.title
    branchUniversalObject.contentDescription = ""
    branchUniversalObject.imageUrl = card.photoURLsProperties.originalURL

    branchUniversalObject.addMetadataKey(CardKeys.cardID.rawValue, value: card.id)

    branchUniversalObject.addMetadataKey("placeAvatarURLString", value: card.photoURLsProperties.originalURL)

    branchUniversalObject.addMetadataKey("title", value: card.title)
    branchUniversalObject.addMetadataKey("isAutoGeneratedCard", value: "false")

    let fullLocationName = card.location.fullLocationName
    branchUniversalObject.addMetadataKey("fullLocationName", value: fullLocationName)

    branchUniversalObject.addMetadataKey(CardKeys.ownerID.rawValue, value: card.ownerID)
    branchUniversalObject.addMetadataKey(ParametersKeywords.type.rawValue, value: ModeKeywords.shareCard.rawValue)

    branchUniversalObject.addMetadataKey("availableSeats", value: card.peopleProperties.availableSeats.description)

    let coordinate = card.location.coordinate
    branchUniversalObject.addMetadataKey("latitude", value: coordinate.latitude.description)
    branchUniversalObject.addMetadataKey("longitude",value: coordinate.longitude.description)

    let linkProperties = BranchLinkProperties()
    linkProperties.feature = "sharing"
    linkProperties.addControlParam("$desktop_url", withValue: "http://www.appname.com")
    linkProperties.addControlParam("$ios_has_app_url", withValue: "appname://")
    linkProperties.addControlParam("$ios_url", withValue: "https://itunes.apple.com/app/idXXXXXXXXXXXXXXX")

    return (branchUniversalObject: branchUniversalObject, branchLinkProperties: linkProperties)
}

Update: My goal is that when the deep link is clicked, if the application is installed, then the application is opened, if not, then the app store link.

Update 1: I changed my code like this and it opens the App Store if I just click on the link, and if I use 3D Touch then I can choose where to open this link. Is it possible to do that if the application is installed and clicking on the link immediately opened the application (or at least a link in the browser, but that there was an option to open the application) and if the application is not installed, then clicking on the link, go to the App Store app page .

let linkProperties = BranchLinkProperties()
        linkProperties.feature = "sharing"
        linkProperties.addControlParam("$desktop_url", withValue: "http://www.appname.com")
        linkProperties.addControlParam("$ios_has_app_url", withValue: "https://appname.app.link/")
        linkProperties.addControlParam("$ios_url", withValue: "itms-apps://itunes.apple.com/app/idXXXXXX")

回答1:


Alex from Branch.io here:

The good news is this is much easier than you're expecting. However, since you made such a complete report, I'll go through all the details so you know exactly what happens behind the scenes.

Short Explanation

To handle launching your app when it is installed, you don't need to manually set your custom URI scheme as the value of $ios_has_app_url — Branch and iOS implement this behavior for you by design.

If your links are not launching your app, you may have a problem with your Universal Links configuration. I recommend reviewing this troubleshooting guide.

Long Explanation

Our $ios_has_app_url control parameter relies on a boolean has_app value tracked by our servers. The has_app value fairly accurate in typical real-world use (plenty good enough for switching a button between displaying an Open or an Install label on a smart app banner, for example), but it's not 100% accurate in all situations.

This is a limitation of iOS: Apple doesn't allow web pages to query for which apps are installed on a device (for obvious privacy reasons), so Branch has to rely on cookie matching. This means if we can't match the cookie, or haven't seen the user recently, or the user clears their device cache, or the user has uninstalled the app since the last time Branch saw them, the value of has_app will be incorrect. When the has_app value is incorrect, then the $ios_has_app_url behavior will also be wrong.

HOWEVER, even though Apple doesn't allow web pages to query access this data, iOS itself can still act on it. Universal Links do exactly this — when the user opens a Universal Link (which includes Branch links, assuming you got all the configuration done), the app will open if it is installed. If it is not installed, the user will be sent to the URL of the link.

Intended use of $ios_has_app_url

The Branch $ios_has_app_url parameter is intended for a very specific usecase in advanced implementations; the vast majority of our partners never use it. Here's the potential situation where you might want it:

You have an edge case where Universal Links are not supported, and you want to send your users to a different web page if Branch knows they have your app installed rather than giving them the option to open it. Obviously this is a rare situation, typically relevant only to enterprise-level apps.

Debugging has_app

If you're stuck trying to debug a situation where has_app is returning the wrong value, you have a couple of options:

  1. If you're getting true and you want false, use Private Browsing mode in Safari. This prevents Branch from making a cookie match, meaning you will always get false.
  2. Alternatively, follow these steps:
    1. Ensure the app that is being tested has setDebug enabled.
    2. Paste a link to a page with the smart banner code into Notes.
    3. Uninstall the app.
    4. Settings > General > Safari > Clear History and Website Data.
    5. Settings > General > Safari > Advanced > Website Data > Swipe left and delete every entry.
    6. Settings > General > Privacy > Advertising > Reset Advertising Identifier...
    7. Click on the link in Notes (from step 1).
    8. The banner should always show "Download" (when it does not, it is because clearing the Website Data was unsuccessful).
    9. Tap on Download.
    10. Run the app via Xcode (serves to install it).
    11. Stop the app in Xcode, then launch it from the phone.
    12. Click on the link in Notes again - the button should now show "Open" and open the app.



回答2:


I see that the browser instead of opening ios_url (App Store link), it tries to open ios_has_app_url. How can I fix it?

By letting the link to be:

"itms-apps://itunes.apple.com/app/idxxxxxxxxxx"


来源:https://stackoverflow.com/questions/45265931/branch-does-not-open-the-app-store-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!