Handle with "App Links" Plugin
To integrate Universal Link in your Flutter project, complete the App Links package integration following App Links.
To capture URLs with the App Links plugin, follow the package's developer guide.
Direct the URLs you captured to the handleUniversalLink method in the Insider plugin in Dart.
final appLinks = AppLinks();
final sub = appLinks.uriLinkStream.listen((uri) {
FlutterInsider.Instance.handleUniversalLink(uri);
print('[INSIDER][uriLinkStream]: $uri');
});If the app is opened with a URL when in a killed state and if the Insider plugin might not collect the universal link via the handleUniversalLink method. This could happen because the Insider SDK has not been initialized yet. In such cases, you can use the above code after Insider plugin initialization or add a delay when calling the handleUniversalLink method.
Handle with Native Methods
Android
If necessary, review the URLs in AndroidManifest.XML. Please check here.
After adding the intent filter to the AndroidManifest.xml, you need to include the Insider handleUniversalLink methods in the MainActivity class as shown below.
If an error occurs during compilation stating that the Insider methods cannot be found, you need to manually add the Insider SDK to the app-level build.gradle file. Make sure the version you add matches the version used in the plugin to avoid any conflicts.
implementation 'com.useinsider:insider:X.X.X'
package com.example.flutter_demo
import android.content.Intent
import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
import com.useinsider.insider.Insider
class MainActivity: FlutterActivity() {
override fun onResume() {
super.onResume()
Insider.Instance.handleUniversalLink(getIntent())
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
Insider.Instance.handleUniversalLink(intent)
}
}iOS
For iOS, the universal link swizzle method works automatically, so no additional action is required on your part. However, if you encounter any issues, you can apply the manual integration as shown below.
Add the Insider handleUniversalLink iOS method in the continueUserActivity method that you added to the AppDelegate.
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
...
}
// For handling universal links
override func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
// For universal links
Insider.handleUniversalLink(userActivity)
return super.application(application, continue: userActivity, restorationHandler: restorationHandler)
}
}