The AppsFlyer URLResolver library is a simple tool to perform redirections of a URL and get a final URL from it.
Install the URLResolver library using Gradle.
Step 1: Declare repositories
In the Project build.gradle
file, declare the mavenCentral
repository:
allprojects {
repositories {
mavenCentral()
}
}
Step 2: Add dependency
In the application build.gradle
file, add the dependency to latest version of library:
dependencies {
implementation 'com.appsflyer:appsflyer-url-resolver:1.0.0'
}
Step 1: Navigate to Add Package Dependency
In Xcode, go to File > Add Packages
Step 2: Add iOS SDK GitHub repository
Enter the AppsFlyer SDK GitHub repository:
https://github.com/AppsFlyerSDK/AppsFlyerURLResolver.git
Step 3: Select SDK version
Step 4: Add AppsFlyerURLResolver to desired Target
Step 1: Download CocoaPods
Download and install the latest version of CocoaPods.
Step 2: Add dependencies
Add the latest version of AppsFlyerURLResolver
to your project's Podfile:
pod 'AppsFlyerURLResolver'
Step 3: Install dependencies
In your terminal, navigate to your project's root folder and run pod install
.
Step 4: Open Xcode workspace
In Xcode, use the .xcworkspace
file to open the project from this point forward, instead of the .xcodeproj
file.
Step 1: Install Carthage
Install the latest version of Carthage.
Step 2: Add dependencies
Add the following line to your Cartfile
:
github "AppsFlyerSDK/AppsFlyerURLResolver" ~> 1.0.0
Method signature
fun resolve(url: String?,maxRedirections: Int = 10, urlResolverListener: URLResolverListener)
Description Resolve a given URL. This function will perform redirects until it gets to the final URL or up to the maximum redirects. The function will return the last URL address.
null
URL will returnnull
.- An invalid URL will return the original input (passed in the
url
parameter).
Input arguments
Type | Name | Description |
---|---|---|
String? | url | The URL to resolve |
Int | maxRedirections | The maximum redirections to relove. The default value is 10 Redirections |
URLResolverListener | urlResolverListener | The listener for the output of the URL resolving |
Example
override fun onDeepLinking(deepLinkResult: DeepLinkResult) {
if (deepLinkResult.status == DeepLinkResult.Status.FOUND) {
URLResolver().resolve(deepLinkResult.deepLink?.deepLinkValue, 5, object : URLResolverListener {
override fun onComplete(url: String?) {
Log.d(TAG, "final URL: $url")
}
})
}
}
Method signature
fun fun resolveJSRedirection(url: String?, urlResolverListener: URLResolverListener)
Description
Use this API if you want to perform redirection based on JS (Hubspot). This api extracts the link from the JS code and returns it to the urlResolverListener
callback for forther redirections.
null
URL will returnnull
.- An invalid URL will return the original input (passed in the
url
parameter).
Input arguments
Type | Name | Description |
---|---|---|
String? | url | The URL to resolve |
URLResolverListener | urlResolverListener | The listener for the output of the URL resolving |
Example
URLResolver(true).resolveJSRedirection("my-url"){
Log.d(TAG, "The URL is: $it")
}
Method signature
resolve(url: String?, maxRedirections: Int = 10 , completionHandler: @escaping (String?) -> Void)
Description Resolve a given URL. This function will perform redirects until to final URL or up to the maximum redirects. The function will return the last URL address using the completion handler.
nil
URL will returnnil
.- Not a vailid URL will return the input to the function (
url
parameter).
Input arguments
Type | Name | Description |
---|---|---|
String? | url | The URL to resolve |
Int | maxRedirections | The maximum redirections to relove. The default value is 10 Redirections |
@escaping (String?) -> Void | completionHandler | Completion handler that will return the result as a optional string |
Example
// add this import
import AppsFlyerURLResolver
func didResolveDeepLink(_ result: DeepLinkResult) {
if result.status == .found{
URLResolver().resolve(url: result.deepLink?.deeplinkValue, maxRedirections: 9){ res in
print("The URL is: \(res ?? "nil")")
}
}
}
Method signature
resolveJSRedirection(url: String?, completionHandler : @escaping (String?) -> Void)
Description
Use this api if you want to perform redirection based on JS. This api extracts the link from the JS code and returns it to the completion handler
for forther redirections.
nil
URL will returnnil
.- Not a vailid URL will return the input to the function (
url
parameter).
Input arguments
Type | Name | Description |
---|---|---|
String? | url | The URL to resolve |
@escaping (String?) -> Void | completionHandler | Completion handler that will return the result as a optional string |
Example
// add this import
import AppsFlyerURLResolver
URLResolver().resolveJSRedirection(url: "my-url"){ res in
print("The URL is: \(res ?? "nil")")
}
The logs are disabled by default.
You can enable the debugging logs by adding true
as the argument for the URLResolver() constructor.
URLResolver(true)
URLResolver(isDebug: true)
🛠 In order for us to provide optimal support, we would kindly ask you to submit any issues to support@appsflyer.com
When submitting an issue please specify your AppsFlyer sign-up (account) email , your app ID , production steps, logs, code snippets and any additional relevant information.