Deeplinking

URLs present in notifications and mobile landings/in-app messages are handled by the Batch SDK in the following ways:

  • the default implementation by the SDK will automatically call -[UIApplication openURL:] with any URL it encounters
  • alternatively you can use a BatchDeeplinkDelegate to handle the URL your way
  • Swift
  • Objective-C
let delegate: BatchDeeplinkDelegate
// deeplinkDelegate is a class property of the Batch class
Batch.deeplinkDelegate = delegate

// Then make your delegate implement the only function from the BatchDeeplinkDelegate protocol
func openBatchDeeplink(_ deeplink: String)

The SDK references your delegate weakly so make sure you hold a strong reference to it. A good idea could be to use your application delegate as the deeplink delegate.

Universal links let you connect to content deep inside your app using standard HTTP or HTTPS links (see documentation on the Apple Developper website).

As Universal links cannot be opened from within an app that supports them using UIApplication.openURL, some extra configuration is needed.

1.18.0 Once you have configured your app to handle universal links, you will need to declare your associated domains to the Batch SDK like in your Associated Domains Entitlement file.

  • Swift
  • Objective-C
class AppDelegate: UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        Batch.setAssociatedDomains(["example.com", "www.example.com"])
        // ...
    }
}

For older SDK versions, you will have to use a BatchDeeplinkDelegate to handle these URLs manually.

If your site uses multiple subdomains (such as example.com, www.example.com, or support.example.com), each requires its own entry like in the Associated Domains Entitlement. Make sure to only include the desired subdomain and the top-level domain. Don’t include path and query components or a trailing slash (/).

Custom URL schemes

Custom URL schemes, like customScheme://first-page, provide a way to reference resoures inside your app (see documentation on the Apple Developper website).

This type of URL is properly handled without a deeplink delegate. However, if you find yourself using a deeplink delegate, you will need to pass your custom-scheme URL manually to -[UIApplication openURL:]. This is a necessary step, considering setting a deeplink delegate overrides the default implementation of the SDK.