ディープリンク
Tauri アプリケーションを URL のデフォルトハンドラとして設定します。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | | Deep links must be registered in config. Dynamic registration at runtime is not supported. |
| android | | Deep links must be registered in config. Dynamic registration at runtime is not supported. |
| ios | | Deep links must be registered in config. Dynamic registration at runtime is not supported. |
ディープリンクプラグインをインストールして開始します。
プロジェクトのパッケージマネージャーを使用して依存関係を追加します。
npm run tauri add deep-linkyarn run tauri add deep-linkpnpm tauri add deep-linkdeno task tauri add deep-linkbun tauri add deep-linkcargo tauri add deep-link-
src-tauriフォルダで次のコマンドを実行して、Cargo.tomlのプロジェクトの依存関係にプラグインを追加します。 -
lib.rsを変更してプラグインを初期化します。src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_deep_link::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
お好みの JavaScript パッケージマネージャーを使用して、JavaScript ゲストバインディングをインストールします。
npm install @tauri-apps/plugin-deep-linkyarn add @tauri-apps/plugin-deep-linkpnpm add @tauri-apps/plugin-deep-linkdeno add npm:@tauri-apps/plugin-deep-linkbun add @tauri-apps/plugin-deep-link
Android でリンクからアプリを開く方法は 2 つあります。
- アプリリンク (http/https + ホスト、検証済み)
アプリリンク の場合、所定の形式でテキスト応答を返す
.well-known/assetlinks.jsonエンドポイントを持つサーバーが必要です。
[ { "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "$APP_BUNDLE_ID", "sha256_cert_fingerprints": [ $CERT_FINGERPRINT ] } }]ここで、$APP_BUNDLE_ID は tauri.conf.json > identifier で定義された値で - を _ に置き換えたものであり、
$CERT_FINGERPRINT はアプリの署名証明書の SHA256 フィンガープリントのリストです。
詳細については、Android アプリリンクの検証 を参照してください。
- カスタム URI スキーム (ホスト不要、検証なし)
myapp://...のような URI の場合、ファイルをホストせずにカスタムスキームを宣言できます。モバイル設定でschemeフィールドを使用し、hostを省略します。
iOS でリンクからアプリを開く方法は 2 つあります。
- ユニバーサルリンク (https + ホスト、検証済み)
ユニバーサルリンク の場合、所定の形式で JSON 応答を返す
.well-known/apple-app-site-associationエンドポイントを持つサーバーが必要です。
{ "applinks": { "details": [ { "appIDs": ["$DEVELOPMENT_TEAM_ID.$APP_BUNDLE_ID"], "components": [ { "/": "/open/*", "comment": "Matches any URL whose path starts with /open/" } ] } ] }}ここで、$DEVELOPMENT_TEAM_ID は tauri.conf.json > tauri > bundle > iOS > developmentTeam または TAURI_APPLE_DEVELOPMENT_TEAM 環境変数で定義された値であり、$APP_BUNDLE_ID は tauri.conf.json > identifier で定義された値です。
ドメインがアプリの関連付けを公開するように適切に設定されているかを確認するには、次のコマンドを実行します(<host> を実際のホストに置き換えてください)。
curl -v https://app-site-association.cdn-apple.com/a/v1/<host>詳細については、applinks.details を参照してください。
- カスタム URI スキーム (ホスト不要、検証なし)
myapp://...のような URI の場合、"appLink": falseでモバイル設定の下にカスタムスキームを宣言できます(または省略します)。プラグインはアプリの Info.plist に適切なCFBundleURLTypesエントリを生成します。.well-knownファイルや HTTPS ホストは必要ありません。
Linux と Windows では、ディープリンクは新しいアプリプロセスのコマンドライン引数として配信されます。 ディープリンクプラグインは、イベントを受信する単一のアプリインスタンスを持つことを好む場合、single instance プラグインと統合されています。
- まず、
deep-link機能を single instance プラグインに追加する必要があります。
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\"))".dependencies]tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] }- 次に、常に登録する最初のプラグインである必要がある single instance プラグインを設定します。
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { let mut builder = tauri::Builder::default();
#[cfg(desktop)] { builder = builder.plugin(tauri_plugin_single_instance::init(|_app, argv, _cwd| { println!("a new app instance was opened with {argv:?} and the deep link event was already triggered"); // ランタイムにディープリンクスキームを定義する場合、ここで `argv` も確認する必要があります })); }
builder = builder.plugin(tauri_plugin_deep_link::init());}tauri.conf.json > plugins > deep-link で、アプリケーションに関連付けるモバイルドメイン/スキームとデスクトップスキームを設定します。
モバイルのカスタムスキーム (サーバー不要):
{ "plugins": { "deep-link": { "mobile": [ { "scheme": ["ovi"], "appLink": false } ] } }}これにより、Android と iOS で ovi://* スキームが登録されます。
アプリリンク / ユニバーサルリンク (検証済み https + ホスト):
{ "plugins": { "deep-link": { "mobile": [ { "scheme": ["https"], "host": "your.website.com", "pathPrefix": ["/open"], "appLink": true } ] } }}これにより、https://your.website.com/open/* がアプリ/ユニバーサルリンクとして登録されます。
デスクトップカスタムスキーム:
{ "plugins": { "deep-link": { "desktop": { "schemes": ["something", "my-tauri-app"] } } }}ディープリンクプラグインは、JavaScript と Rust の両方で使用できます。
アプリの実行中にディープリンクがトリガーされると、onOpenUrl コールバックが呼び出されます。アプリがディープリンク経由で開かれたかどうかを検出するには、アプリの起動時に getCurrent を使用します。
import { getCurrent, onOpenUrl } from '@tauri-apps/plugin-deep-link';// `"withGlobalTauri": true` を使用する場合、以下を使用できます// const { getCurrent, onOpenUrl } = window.__TAURI__.deepLink;
const startUrls = await getCurrent();if (startUrls) { // アプリはおそらくディープリンク経由で起動されました // getCurrent の戻り値は、onOpenUrl がトリガーされるたびに更新されることにも注意してください。}
await onOpenUrl((urls) => { console.log('deep link:', urls);});アプリの実行中にディープリンクがトリガーされると、プラグインの on_open_url クロージャが呼び出されます。アプリがディープリンク経由で開かれたかどうかを検出するには、アプリの起動時に get_current を使用します。
use tauri_plugin_deep_link::DeepLinkExt;
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_deep_link::init()) .setup(|app| { // get_current の戻り値は、on_open_url がトリガーされるたびに更新されることにも注意してください。 let start_urls = app.deep_link().get_current()?; if let Some(urls) = start_urls { // アプリはおそらくディープリンクによって起動されました println!("deep link URLs: {:?}", urls); }
app.deep_link().on_open_url(|event| { println!("deep link URLs: {:?}", event.urls()); }); Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}設定 セクションでは、アプリケーションの静的ディープリンクスキームを定義する方法について説明しています。
Linux と Windows では、register Rust 関数を介してランタイムにアプリケーションにスキームを関連付けることも可能です。
次のスニペットでは、ランタイムに my-app スキームを登録します。アプリを初めて実行した後、オペレーティングシステムは my-app://* URL をアプリケーションで開きます。
use tauri_plugin_deep_link::DeepLinkExt;
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_deep_link::init()) .setup(|app| { #[cfg(desktop)] app.deep_link().register("my-app")?; Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}アプリケーションのディープリンクをテストするには、いくつかの注意点があります。
ディープリンクは、デスクトップにインストールされたアプリケーションに対してのみトリガーされます。
Linux と Windows では、register_all Rust 関数を使用してこれを回避できます。これは、構成されたすべてのスキームを登録して現在の実行可能ファイルをトリガーします。
use tauri_plugin_deep_link::DeepLinkExt;
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_deep_link::init()) .setup(|app| { #[cfg(any(windows, target_os = "linux"))] { use tauri_plugin_deep_link::DeepLinkExt; app.deep_link().register_all()?; } Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}Windows でディープリンクをトリガーするには、ブラウザで <scheme>://url を開くか、ターミナルで次のコマンドを実行します。
start <scheme>://urlLinux でディープリンクをトリガーするには、ブラウザで <scheme>://url を開くか、ターミナルで xdg-open を実行します。
xdg-open <scheme>://urliOS でアプリリンクをトリガーするには、ブラウザで https://<host>/path URL を開くことができます。シミュレーターの場合、simctl CLI を利用してターミナルからリンクを直接開くことができます。
xcrun simctl openurl booted https://<host>/pathAndroid でアプリリンクをトリガーするには、ブラウザで https://<host>/path URL を開くことができます。エミュレーターの場合、adb CLI を利用してターミナルからリンクを直接開くことができます。
adb shell am start -a android.intent.action.VIEW -d https://<host>/path <bundle-identifier>デフォルトでは、すべての潜在的に危険なプラグインコマンドとスコープはブロックされており、アクセスできません。これらを有効にするには、capabilities 設定の権限を変更する必要があります。
詳細については、機能の概要 と、プラグイン権限を使用するための ステップバイステップガイド を参照してください。
{ "$schema": "../gen/schemas/mobile-schema.json", "identifier": "mobile-capability", "windows": ["main"], "platforms": ["iOS", "android"], "permissions": [ // 通常、ディープリンクイベントをリッスンするには core:event:default が必要です "core:event:default", "deep-link:default" ]}Default Permission
Allows reading the opened deep link via the get_current command
This default permission set includes the following:
allow-get-current
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the get_current command without any pre-configured scope. |
|
|
Denies the get_current command without any pre-configured scope. |
|
|
Enables the is_registered command without any pre-configured scope. |
|
|
Denies the is_registered command without any pre-configured scope. |
|
|
Enables the register command without any pre-configured scope. |
|
|
Denies the register command without any pre-configured scope. |
|
|
Enables the unregister command without any pre-configured scope. |
|
|
Denies the unregister command without any pre-configured scope. |
© 2025 Tauri Contributors. CC-BY / MIT