Created
October 23, 2018 09:23
-
-
Save martinpilch/e3b71a69f0aabdb2873c2df868280472 to your computer and use it in GitHub Desktop.
Content of onAppOpenAttribution function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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