flutter 开启 deeplinking 配置记录

deeplinking 可以使用 scheme 的方式拉起 android 或者 ios 的指定页面。

ios

info.plist

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <!-- 起作用的部分  开始-->
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>movieapps</string>
            </array>
			<key>CFBundleURLName</key>
			<string>com.example</string>
		</dict>
	</array>
	<key>FlutterDeepLinkingEnabled</key>
        <true/>
        <!-- 起作用的部分  结束-->
    
	<key>CADisableMinimumFrameDurationOnPhone</key>
	<true/>
	<key>CFBundleDevelopmentRegion</key>
	<string>$(DEVELOPMENT_LANGUAGE)</string>
	<key>CFBundleDisplayName</key>
	<string>Movies</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>movies</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>$(FLUTTER_BUILD_NAME)</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>$(FLUTTER_BUILD_NUMBER)</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>UIApplicationSceneManifest</key>
	<dict>
		<key>UIApplicationSupportsMultipleScenes</key>
		<false/>
		<key>UISceneConfigurations</key>
		<dict>
			<key>UIWindowSceneSessionRoleApplication</key>
			<array>
				<dict>
					<key>UISceneClassName</key>
					<string>UIWindowScene</string>
					<key>UISceneConfigurationName</key>
					<string>flutter</string>
					<key>UISceneDelegateClassName</key>
					<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
					<key>UISceneStoryboardFile</key>
					<string>Main</string>
				</dict>
			</array>
		</dict>
	</dict>
	<key>UIApplicationSupportsIndirectInputEvents</key>
	<true/>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIMainStoryboardFile</key>
	<string>Main</string>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
</dict>
</plist>

测试方法1:

rust 复制代码
xcrun simctl openurl booted 'movieapps://example.com/details/1'

测试方法2: 使用 ios 默认浏览器打开 movieapps://example.com/details/1

android

xml 复制代码
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application
        android:label="movies"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:taskAffinity=""
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <!-- 起作用的部分  开始-->
            <meta-data
                android:name="flutter_deeplinking_enabled"
                android:value="true" />

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="movieapp" android:host="example.com"/>
            </intent-filter>
            <!-- 起作用的部分  结束-->
            <!--
            在终端测试 deep-link
            adb shell 'am start -a android.intent.action.VIEW \
			  -c android.intent.category.BROWSABLE \
			  -d "movieapp://example.com/details/1"' \
			com.example.movies/.MainActivity
            
              -->

        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
    <!-- Required to query activities that can process text, see:
         https://developer.android.com/training/package-visibility and
         https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.

         In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
    <queries>
        <intent>
            <action android:name="android.intent.action.PROCESS_TEXT"/>
            <data android:mimeType="text/plain"/>
        </intent>
    </queries>
</manifest>

测试方法1:

vbnet 复制代码
adb shell 'am start -a android.intent.action.VIEW \
			  -c android.intent.category.BROWSABLE \
			  -d "movieapp://example.com/details/1"' \
			com.example.movies/.MainActivity

测试方法2: 使用 android 默认浏览器打开 movieapps://example.com/details/1

相关推荐
500848 小时前
HCCL 集合通信编程:多卡协同的正确姿势
java·flutter·性能优化·electron·wpf
你听得到1110 小时前
从 Figma 走查到 AI 可验证产物:我如何重构客户端 UI 交付链路
前端·vue.js·flutter
song50112 小时前
昇腾 910 的硬件架构:为什么它适合跑大模型
图像处理·人工智能·分布式·flutter·硬件架构·交互
恋猫de小郭12 小时前
Dart 大更新,新增语法糖和各种能力,真的难得了
android·前端·flutter
莞凰1 天前
昇腾CANN的“御剑飞行“:ATB仓库探秘
人工智能·flutter·transformer
QQ3463481571 天前
Flutter_01 工具准备1
flutter
QQ3463481571 天前
Flutter_02 工具准备2-2
flutter
淡写成灰1 天前
造一个生产级 Flutter WebSocket 客户端:适配器模式 + 七大企业特性全解析
flutter
水云桐程序员2 天前
Flutter与React Native的对比分析
flutter·react native·react.js