Skip to content

Instantly share code, notes, and snippets.

@martinpilch
Created October 23, 2018 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinpilch/e3b71a69f0aabdb2873c2df868280472 to your computer and use it in GitHub Desktop.
Save martinpilch/e3b71a69f0aabdb2873c2df868280472 to your computer and use it in GitHub Desktop.
Content of onAppOpenAttribution function
func onAppOpenAttribution(_ attributionData: [AnyHashable: Any]) {
// If opening app from onelink shortlink we check for `af_dp` property
if let deeplink = attributionData[Keys.deeplink] as? String,
let deeplinkURL = URL(string: deeplink) {
delegate?.setDeeplinkURL(deeplinkURL)
return
}
// Else we get `link` property and and parse it's params
guard let link = attributionData[Keys.link] as? String,
let linkURL = URL(string: link)
else { return }
// Parse link and get item `af_dp`from query items
let components = URLComponents(url: linkURL, resolvingAgainstBaseURL: false)
let deeplinkComponent = components?.queryItems?.first(where: { item -> Bool in
return item.name == Keys.deeplink
})
// Create an URL and send to delegate
guard let deeplink = deeplinkComponent?.value,
let deeplinkURL = URL(string: deeplink)
else { return }
delegate?.setDeeplinkURL(deeplinkURL)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment