← All guides

Deferred deep linking on iOS without an MMP

Published · Last verified

Universal Links open your app when it is installed. When it isn't, iOS opens the link in the browser, the person installs from the App Store, and your app starts on its home screen. The link they tapped is gone. Deferred deep linking carries that link through the install, so the first launch can open the right screen.

This guide is for small teams with a native iOS app who want that without a mobile measurement partner (MMP). Grivn is our product. It is not an MMP: it doesn't attribute paid-ad installs or report SKAdNetwork. On iOS it offers a native Swift SDK; there is no Flutter or React Native SDK.

The options

Option How the app gets the link Trade-offs
Pasteboard Your web page copies the link before sending people to the App Store. The app reads it on first launch. Exact, no guessing. Since iOS 16, reading the pasteboard in code shows a permission alert; the system paste button avoids it but needs a tap. Lost if the person copies something else first.
Your own server-side matching Your server records each click's network and device details and compares them with the app's first request. Nothing for the user to do, but it's a guess: on a shared network it can pick the wrong device. You build and run it. Apple prohibits fingerprinting.
App Clip The link opens an App Clip, which receives the URL and saves it to a shared App Group. The full app reads it after install. Exact. Needs a second target, App Clip experiences in App Store Connect and a size limit. Works just for people who open the clip before installing.

Grivn does the second option for you, with the same limits, and adds the pasteboard as a fallback: its link preview page copies the link (a checkbox the visitor can untick), and the SDK reads it when the user taps.

How Grivn matches, and what it can't do

When someone without your app taps a Grivn link on an iPhone or iPad, the browser shows Grivn's preview page. Tapping OPEN goes to the App Store, and Grivn keeps that click for 48 hours.

On the first launch after install, the SDK sends a User-Agent (device model, iOS version, app name and version) and the device language. Grivn also sees the request IP address. It looks for a recent click from the same device type (phone or tablet) and OS, plus either the exact IP address within 48 hours, or the same /24 range and device language within 2 hours. Without a network match there is no match. The SDK computes no device identifier, and each click is handed out once.

This is probabilistic. On a shared network (an office, a campus) it can match a click made on another device. Treat a match as a hint: open the screen, but don't grant referral rewards or link accounts on a match alone.

Apple's User Privacy and Data Use page prohibits deriving data from a device to uniquely identify it, and says apps that use SDKs which do may be rejected. App Review has rejected apps for SDKs that match with probabilistic methods. Grivn uses coarse signals and short-lived records, but whether that is acceptable for your app is your call. To turn matching off, call this before initialize:

DynamicLinksSDK.setAnalyticsEnabled(false)

The SDK then makes no deferred lookup and sends no events. Universal Links still work, and so does the pasteboard fallback in step 5.

Set it up

1. Create a project and a link

In the Grivn dashboard, create a project with your iOS App ID in the form TEAMID.com.example.app (Team ID from Apple Developer → Membership, bundle ID from Xcode → Target → General). Grivn then serves the apple-app-site-association file on your link domain (the host of your short links, YOUR_PROJECT_ID.grivn.com) for every path.

Create a link. Set Deep Link URL to the address of the screen in your app, for example https://example.com/product/123, and iOS App Store ID to your app's numeric ID. Leave iOS Fallback Link empty: people sent to a web page get no deferred link.

Then create a publishable key in Settings → API Keys → Publishable.

2. Add the Associated Domains entitlement

In Xcode, open your target's Signing & Capabilities tab, add Associated Domains, and add:

applinks:YOUR_PROJECT_ID.grivn.com

Write just the host, with no path, query or trailing slash. If your links use your own domain, add that one too.

3. Add the SDK

In Xcode, choose File → Add Package Dependencies, enter https://github.com/Grivn-com/Grivn-Deeplink-iOS-SDK.git, pick version 1.4.0 or later, and add the DynamicLinks library to your app target. It supports iOS 13 and later.

4. Initialize with the deferred callback

import UIKit
import DynamicLinks

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        DynamicLinksSDK.initialize(
            baseUrl: "https://api.grivn.com",
            secretKey: "grivn_pk_YOUR_PUBLISHABLE_KEY", // publishable key, never grivn_sk_
            projectId: "YOUR_PROJECT_ID"
        ) { result in
            // Runs on the main thread at every launch. found is true at most
            // once: on the first launch after install, when a click matched.
            guard result.found,
                  let tapped = result.originalUrl.flatMap({ URL(string: $0) }) else { return }
            Task { @MainActor in
                await LinkRouter.shared.open(tapped)
            }
        }
        // After initialize: links on any other host are rejected.
        DynamicLinksSDK.configure(allowedHosts: ["YOUR_PROJECT_ID.grivn.com"])
        return true
    }
}
  • initialize always runs the first-launch check, so this callback is how you get the result. Calling checkDeferredDeeplink() yourself later returns found == false.
  • originalUrl is the Grivn link the person tapped (with ?from-preview=true added), not your destination. Resolve it the same way as a Universal Link (next step).
  • The key ships inside your app, so it must be a publishable key (grivn_pk_). It can resolve and create links and report installs and events, nothing more. Never put a secret key (grivn_sk_) in an app: anyone can extract it, and the SDK endpoints reject it. The parameter is still named secretKey for compatibility.

5. Route links in one place

Both paths hand you a Grivn link. handleDynamicLink turns it into the Deep Link URL you set:

import UIKit
import DynamicLinks

@MainActor
final class LinkRouter {
    static let shared = LinkRouter()

    /// Opens a Grivn link, whether it came from a Universal Link or a deferred match.
    func open(_ link: URL) async {
        do {
            let resolved = try await DynamicLinksSDK.shared.handleDynamicLink(link)
            guard let destination = resolved.url else { return }
            show(destination)
        } catch {
            // Unknown host, deleted link, or no network: stay on the home screen.
        }
    }

    func show(_ destination: URL) {
        // destination is the Deep Link URL you set on the link,
        // e.g. https://example.com/product/123
        let parts = destination.pathComponents // ["/", "product", "123"]
        if parts.count == 3, parts[1] == "product" {
            // push your product screen for parts[2]
        }
    }
}

With scenes, Universal Links arrive in two places: scene(_:willConnectTo:options:) when the app wasn't running, and scene(_:continue:) when it was. Handle both:

import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    // The app wasn't running when the link was tapped.
    func scene(
        _ scene: UIScene,
        willConnectTo session: UISceneSession,
        options connectionOptions: UIScene.ConnectionOptions
    ) {
        // ...set up your window as usual...
        if let activity = connectionOptions.userActivities.first(where: {
            $0.activityType == NSUserActivityTypeBrowsingWeb
        }), let url = activity.webpageURL {
            Task { await LinkRouter.shared.open(url) }
        }
    }

    // The app was running or suspended.
    func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
        guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
              let url = userActivity.webpageURL else { return }
        Task { await LinkRouter.shared.open(url) }
    }
}

An app without scenes gets the link in application(_:continue:restorationHandler:) instead. In a SwiftUI app, attach the app delegate above (without @main) with @UIApplicationDelegateAdaptor, and use onOpenURL, which receives Universal Links as URLs:

import SwiftUI

@main
struct MyApp: App {
    @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate

    var body: some Scene {
        WindowGroup {
            ContentView()
                .onOpenURL { url in
                    Task { await LinkRouter.shared.open(url) }
                }
        }
    }
}

Optional pasteboard fallback. If the visitor tapped OPEN with the preview page's checkbox ticked, the link is on the pasteboard. It helps when matching is off or found nothing. Checking whether the pasteboard holds a URL shows no prompt; reading it does, so read it when the user taps:

// No paste prompt: only checks whether the pasteboard holds a URL.
if DynamicLinksSDK.shared.hasPossibleDynamicLink() {
    // show a "Continue where you left off" button
}

// In that button's action. iOS shows its paste prompt here.
Task {
    if let link = try? await DynamicLinksSDK.shared.handlePasteboardDynamicLink(),
       let destination = link.url {
        LinkRouter.shared.show(destination)
    }
}

6. Test

Universal Links, with the app installed. On a device, paste a link into Notes and long-press it. If the setup is right, you get options to open it in your app or in the browser (TN3155). With Developer Mode on, Settings → Developer → Associated Domains Development → Diagnostics checks a URL against your installed app.

Deferred links. You don't need an App Store release:

  1. Use a device or Simulator that doesn't have your app. On a device, turn off iCloud Private Relay (see the pitfalls).
  2. Open the link in Safari there and tap OPEN on the preview page. Stop at the App Store page. The Simulator has no App Store, so Safari says it can't open the address instead; that's expected, and the click is already saved.
  3. Within 48 hours, on the same network, run your app from Xcode. Calling DynamicLinksSDK.setDebugMode(true) before initialize logs the lookup with a [GrivnSDK] tag in Xcode's console. Outside Xcode, filter Console.app or log stream by the subsystem com.grivn.dynamiclinks.

This works in the Simulator as well as on a device; we run it there.

To repeat the first-launch lookup without reinstalling, tap the link again (each click is handed out once), then run this from a debug-only button:

#if DEBUG
Task {
    let result = try await DynamicLinksSDK.shared.checkDeferredDeeplink(forceCheck: true)
    if result.found, let tapped = result.originalUrl.flatMap({ URL(string: $0) }) {
        await LinkRouter.shared.open(tapped)
    }
}
#endif

Moving from Firebase Dynamic Links

Grivn's iOS SDK keeps the Firebase Dynamic Links names where it can, so most of the move is renaming calls:

Firebase Dynamic Links Grivn (import DynamicLinks)
First-open link arrives in application(_:open:options:) as a custom-scheme URL, read with dynamicLink(fromCustomSchemeURL:) The onDeferredDeeplink callback of DynamicLinksSDK.initialize, then handleDynamicLink on its originalUrl (steps 4 and 5)
DynamicLinks.dynamicLinks().handleUniversalLink(_:completion:) try await DynamicLinksSDK.shared.handleDynamicLink(_:)
DynamicLink.url, utmParametersDictionary, minimumAppVersion DynamicLink.url, utmParameters, minimumAppVersion
DynamicLinkComponents(link:domainURIPrefix:), then shorten DynamicLinkComponents(link:domainURIPrefix:), then try await DynamicLinksSDK.shared.shorten(dynamicLink:)
DynamicLinkGoogleAnalyticsParameters DynamicLinkAnalyticsParameters
components.url (a long link) Always shorten: Grivn serves short links only
FirebaseDynamicLinksCustomDomains in Info.plist DynamicLinksSDK.configure(allowedHosts:)
Custom URL scheme links None: Grivn uses Universal Links only
applinks:yourapp.page.link applinks:YOUR_PROJECT_ID.grivn.com, or your own domain

Your existing links:

  • On your own domain (for example links.example.com): import them into Grivn with their short codes, then point the domain at Grivn. The migration guide covers the import.
  • On page.link: they can't move, because Google owns that domain. Share new Grivn links from now on.
  • Long links built in code (https://your.domain/?link=…): they don't carry over. Change that code to call shorten.

Common pitfalls

  • A fallback link, or no App Store ID. Clicks that go to a web page aren't kept for matching.
  • iOS App ID missing or wrong in Grivn. Grivn returns an error instead of the apple-app-site-association file, and Universal Links never open the app.
  • Expecting association changes right away. Since iOS 14, devices get the file from Apple's CDN, which requests it within 24 hours. Installed devices check about once a week; reinstalling the app fetches it again (TN3155). While developing, applinks:YOUR_PROJECT_ID.grivn.com?mode=developer skips the CDN for development-signed builds on devices that opted in. Devices not in developer mode can't use that entry, so remove it before release.
  • Typing the link into Safari's address bar. That never opens the app. Neither does tapping a link to the same domain as the page you're on.
  • Choosing the browser on a long-press. iOS keeps that choice as the default for the domain (TN3155). Long-press again and choose your app to undo it.
  • Other browsers. Support for Universal Links in third-party browsers is up to each browser.
  • configure(allowedHosts:) missing, or called before initialize. Every link is rejected as invalid. List every host your links use, including your own domain.
  • Handling only scene(_:continue:). Links that start the app from cold are missed.
  • No match although the setup is right. Common causes:
    • iCloud Private Relay covers Safari browsing but not your app's HTTPS requests, so the two IP addresses differ.
    • The tap and the first launch came from different networks, for example Wi-Fi and then cellular.
    • The click is more than 48 hours old.
    • The visitor's browser sent Global Privacy Control, or they opted out of attribution. Grivn then keeps no click to match.
    • On the free Hacker plan, the project passed 1,000 clicks this month. Links keep working, but attribution, deferred matching included, pauses until next month.
  • Rewarding on a match. A match can be someone else's device on the same network. Confirm referrals another way.

What it costs

Grivn's Hacker plan is free for 1,000 clicks a month, Growth is $19/month and Pro is $99/month. Start free.