Deep Link Native App
Follow the steps to set up deep-linking for your app.
Last updated
import Foundation
enum DeepLink: String {
case home
case detail
} func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// Process the URL.
guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
let host = components.host else {
print("Invalid URL")
return false
}
print("components: \(components)")
// Create the deep link
guard let deeplink = DeepLink(rawValue: host) else {
print("Deeplink not found: \(host)")
return false
}
// Hand off to mainViewController
mainViewController.handleDeepLink(deeplink)
return true
}// MARK: Deep Link
extension MainViewController {
func handleDeepLink(_ deepLink: DeepLink) {
switch deepLink {
case .home:
// handle show your app's home screen here
case .detail:
// handle show your app's detail screen here
default:
// handle the PAVE's Session ID here
}
}
} <application
...>
<activity
android:name=".MainActivity"
android:label="MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="PAVE Filter">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "pave://...” -->
<data android:scheme="pave" />
</intent-filter>
</activity>
</application>override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
val appLinkAction: String? = intent?.action
val appLinkData: Uri? = intent?.data
if (Intent.ACTION_VIEW == appLinkAction && appLinkData != null) {
val sessionId = appLinkData.getQueryParameter("sessionId")
if (sessionId.isNullOrBlank().not()) {
// handle the PAVE's Session ID here
}
}
}