Deep linking
The Affise SDK provides callbacks for both custom-scheme deep links and Universal Links, and can report a deferred deep link surfaced by attribution.
- Register callback:
@objc public static func registerDeeplinkCallback(_ callback: OnDeeplinkCallback?)—AffiseAttributionLib/Classes/Affise.swift:60-62 - Callback type:
public typealias OnDeeplinkCallback = (_ value: DeeplinkValue) -> Void—AffiseAttributionLib/Classes/deeplink/DeeplinkManager.swift:8 - Feed URL:
@objc public static func handleDeeplink(_ url: URL?)—AffiseAttributionLib/Classes/internal/InternalAffise.swift:9-12 - Feed
NSUserActivity:@objc public static func handleUserActivity(_ userActivity: NSUserActivity)—AffiseAttributionLib/Classes/internal/InternalAffise.swift:25-31
Custom-scheme deep links
Section titled “Custom-scheme deep links”Register the callback
Section titled “Register the callback”Call registerDeeplinkCallback after start(...):
Affise.settings(affiseAppId: affiseAppId, secretKey: secretKey).start(app: app, launchOptions: launchOptions)Affise.registerDeeplinkCallback { value in // full uri "scheme://host/path?parameters" let deeplink = value.deeplink
// separated for convenience let scheme = value.scheme let host = value.host let path = value.path let queryParametersMap = value.parameters
if queryParametersMap["<your_uri_key>"].contains("<your_uri_key_value>") == true { // handle value }}Forward URLs to the SDK
Section titled “Forward URLs to the SDK”In your UIApplicationDelegate, forward the incoming URL via handleDeeplink:
func application( _ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { Affise.handleDeeplink(url) return true}DeeplinkValue fields
Section titled “DeeplinkValue fields”From AffiseAttributionLib/Classes/deeplink/DeeplinkValue.swift:5-26:
| Field | Type | Description |
|---|---|---|
| deeplink | String | Full URI (scheme://host/path?parameters). |
| scheme | String? | URI scheme. |
| host | String? | URI host. |
| path | String? | URI path. |
| parameters | [String: [String]] | Multi-valued query parameters. |
An extension Optional where Wrapped == URL → public func toDeeplinkValue() -> DeeplinkValue is available at DeeplinkValue.swift:35.
Universal Links (AppLinks)
Section titled “Universal Links (AppLinks)”Set up an apple-app-site-association file as usual, then forward NSUserActivity to the SDK. The handleUserActivity call internally invokes both handleReferrer(userActivity.referrerURL) and handleDeeplink(userActivity.webpageURL) (AffiseAttributionLib/Classes/internal/InternalAffise.swift:25-31).
Verbatim:
func application( _ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { Affise.handleUserActivity(userActivity) return true}Get deferred deep link
Section titled “Get deferred deep link”- API:
@objc public static func getDeferredDeeplink(_ callback: @escaping OnReferrerCallback)—AffiseAttributionLib/Classes/Affise.swift:147-150 - Callback:
public typealias OnReferrerCallback = (_ value: String?) -> Void—AffiseAttributionLib/Classes/referrer/OnReferrerCallback.swift:1
Verbatim:
Affise.getDeferredDeeplink { deferredDeeplink in // handle deferred deeplink}Get deferred deep link value
Section titled “Get deferred deep link value”API: @objc public static func getDeferredDeeplinkValue(_ key: ReferrerKey, _ callback: @escaping OnReferrerCallback) — AffiseAttributionLib/Classes/Affise.swift:155-158.
Verbatim:
Affise.getDeferredDeeplinkValue(ReferrerKey.CLICK_ID) { deferredDeeplinkValue in // handle deferred deeplink value}See Referrer for the full ReferrerKey enumeration.