Safari cannot open the page - The error was, "The URL can't be shown" - related to Deeplinks?

Viewed 3177

So I am trying to use deeplinks in an iOS app like so (note, domain here is a dummy value):

static let redirectUrlStr = "domain://domain:success"

And

private let redirectUrl = URL(string: .redirectUrlStr)!

And I am passing this as a redirect to an AppAuth request:

let request = OIDTokenRequest(configuration: config!,
                              grantType: .refreshGrantType,
                              authorizationCode: nil,
                              redirectURL: self.redirectUrl,
                              clientID: .clientId,
                              clientSecret: nil,
                              scopes: [OIDScopeOpenID, OIDScopeProfile, OIDScopeEmail],
                              refreshToken: userCredentials.refreshToken,
                              codeVerifier: nil,
                              additionalParameters: nil)

This part all seems to work, and if I pass in a redirect URL like google.com, the redirect to google works.

However when attempting to use deeplinking I get the above error.

Now I think this should work -

I've got associated domains enabled in the capabilities portion of Xcode as such:

applinks:domain.com

And I have associated domains enabled in the App ID on Apple Developer

What is missing here? Do I need an apple-app-site-association file?

I've only worked with deeplinking once before so I'm not too clear on what I might be missing.

There is also an entitlements file with the associated domain information too.

4 Answers

If you want to call your app with URL, you have to set URLType in your project info:

enter image description here

Note that you have to choose editor as Role of your URL scheme. Now you can call your app with domain:// and you can follow this url with any query or path parameters you what to pass to your app like: domain://users?id=12

If you need your original domain to forward to your app, for example: www.domain.com/users instead of domain://users, YES you need an apple-app-site-association uploaded to root of your host. So iOS can detect it and if user prefers, your app will open and the corresponding url passed to your application.

Both of these methods has it's own cons and pros. Instagram and AppStore use their original domain with an apple-app-site-association file associated. But Google is using URL scheme for tasks like google sign-in enter image description here

I think this might be related with your app's URL Scheme handling. If you don't update your plist to inform operating system about your handling of domain URL scheme then it'll be seen as a mistyped URL. Try to add domain to your URL Types -> URL Schemes of your Info.plist file. You can do this via:

  <key>CFBundleURLTypes</key>
  <array>
    <dict>
        <key>CFBundleURLName</key>
        <string>com.domain</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>domain</string>
        </array>
    </dict>
  </array>

Hope this helps.

Hi there I am using a deep-link url generate by fire base.

I can open this url in google and safari my code is

/// Deepl link Shared Link
    func deepLinkShare(_ data: CSSharedObject, sender: Any, isVideoDetail: Bool = false) {
        let button = sender as? UIButton
        button?.startAnimating()
        let videoLink = SHAREURL + "video/" + data.videoSlug + "?videoId=" + String(data.videoId)
        guard let link = URL(string: videoLink) else { return }
        let dynamicLinksDomain = DEEPLINKDOMAIN
        let linkBuilder = DynamicLinkComponents(link: link, domain: dynamicLinksDomain)
        linkBuilder.iOSParameters = DynamicLinkIOSParameters.init(bundleID: Bundle.main.bundleIdentifier!)
        linkBuilder.iOSParameters?.customScheme = CUSTOMURLSCHEME
        linkBuilder.iOSParameters?.minimumAppVersion = "1.0"
        linkBuilder.navigationInfoParameters?.isForcedRedirectEnabled = false
        linkBuilder.iOSParameters?.appStoreID = "123456789"
        linkBuilder.analyticsParameters = DynamicLinkGoogleAnalyticsParameters(source: "asfdsf",
                                                                               medium: "video",
                                                                               campaign: "Share")
        linkBuilder.socialMetaTagParameters = DynamicLinkSocialMetaTagParameters()
        linkBuilder.socialMetaTagParameters?.title = data.videoTitle
        linkBuilder.socialMetaTagParameters?.descriptionText = data.videoShortDescription
        linkBuilder.socialMetaTagParameters?.imageURL = data.thumbNailimage
        linkBuilder.androidParameters = DynamicLinkAndroidParameters(packageName: ANDROIDAPPBUNDLE)
        linkBuilder.options = DynamicLinkComponentsOptions()
        linkBuilder.options?.pathLength = .short
        guard let longDynamicLink = linkBuilder.url else { return }
        DynamicLinkComponents.shortenURL(longDynamicLink, options: nil) { url, _, error in
            button?.stopAnimating()
            guard let url = url, error == nil else { return }
            /// item to be shared
            let shareItems: Array = [url.absoluteString] as [Any]
            self.openSharePopUp(sender, sharedItems: shareItems, isVideoDetail: isVideoDetail)
        }
    }
  1. CSShared Object is one which has a custom object
  2. data.videoSlug is the item data which is used to construct url
  3. DEEPLINKDOMAIN is the domain of deeplink Domain generate by fire base it
  4. CUSTOMURLSCHEME is the custom scheme generate for that particular application

This then can be opened in application by using the delegate of fire base Dynamic linking

func application(_ application: UIApplication, open url: URL, sourceApplication: String?,
                     annotation: Any) -> Bool {
        if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
            /// Open the dynamic link url in your application

            return true
        }
    }

The answer is that due to the URL scheme identifier already existing in the App Store, it is considered a duplicate and this is causing what Apple describes as, "odd behavior".

Switching to a more unique URL scheme identifier fixed the problem immediately.

Related