본문으로 건너뛰기
엔지니어링 · · 6분 소요

.NET MAUI 딥 링킹: 구현 가이드

작성자 Tolinku 팀
|
.NET MAUI 딥 링킹 구현 가이드

.NET MAUI(Multi-platform App UI)는 Xamarin.Forms의 후속 프레임워크예요. C# 코드베이스 하나로 iOS, Android, macOS, Windows를 지원하고, 플랫폼별 코드는 Platforms/ 디렉터리에 따로 둬요. MAUI의 딥 링킹도 같은 네이티브 방식(iOS는 Universal Links, Android는 App Links)을 따르지만, MAUI의 Shell 내비게이션과 의존성 주입에 맞춰 연동돼요.

Xamarin.Forms(레거시)는 다음 문서를 참고하세요: Xamarin 딥 링킹: 크로스 플랫폼 설정. 크로스 플랫폼 개요는 다음 글을 참고하세요: 2026년 크로스 플랫폼 딥 링킹 가이드.

iOS 설정

1. Associated Domains 엔타이틀먼트

다음 파일을 만들거나 수정하세요: Platforms/iOS/Entitlements.plist:

<?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>com.apple.developer.associated-domains</key>
    <array>
        <string>applinks:yourdomain.com</string>
    </array>
</dict>
</plist>

다음 파일에서 이 파일을 참조하세요: .csproj:

<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
    <CodesignEntitlements>Platforms/iOS/Entitlements.plist</CodesignEntitlements>
</PropertyGroup>

2. AASA 파일

다음 위치에 호스팅하세요: https://yourdomain.com/.well-known/apple-app-site-association:

{
  "applinks": {
    "details": [{
      "appIDs": ["TEAMID.com.yourcompany.yourapp"],
      "components": [
        { "/": "/products/*" },
        { "/": "/offers/*" },
        { "/": "/referral/*" }
      ]
    }]
  }
}

Team ID는 Apple Developer 계정 의 Membership Details에서 확인할 수 있어요.

수정할 파일: Platforms/iOS/AppDelegate.cs:

using Foundation;
using UIKit;

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
    protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

    [Export("application:continueUserActivity:restorationHandler:")]
    public bool ContinueUserActivity(
        UIApplication application,
        NSUserActivity userActivity,
        UIApplicationRestorationHandler completionHandler)
    {
        if (userActivity.ActivityType == NSUserActivityType.BrowsingWeb
            && userActivity.WebPageUrl != null)
        {
            var url = userActivity.WebPageUrl.ToString();
            DeepLinkService.Instance.HandleUrl(url);
            return true;
        }
        return false;
    }
}

Android 설정

1. 인텐트 필터

수정할 파일: Platforms/Android/AndroidManifest.xml:

<activity
    android:name=".MainActivity"
    android:exported="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="https"
              android:host="yourdomain.com"
              android:pathPrefix="/products" />
        <data android:scheme="https"
              android:host="yourdomain.com"
              android:pathPrefix="/offers" />
        <data android:scheme="https"
              android:host="yourdomain.com"
              android:pathPrefix="/referral" />
    </intent-filter>
</activity>

또는 IntentFilter 속성을 다음 파일에 붙여도 돼요: MainActivity.cs:

using Android.App;
using Android.Content;
using Android.Content.PM;

[Activity(
    Theme = "@style/Maui.SplashTheme",
    MainLauncher = true,
    Exported = true,
    LaunchMode = LaunchMode.SingleTop)]
[IntentFilter(
    new[] { Intent.ActionView },
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataScheme = "https",
    DataHost = "yourdomain.com",
    DataPathPrefix = "/products",
    AutoVerify = true)]
[IntentFilter(
    new[] { Intent.ActionView },
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataScheme = "https",
    DataHost = "yourdomain.com",
    DataPathPrefix = "/offers",
    AutoVerify = true)]
[IntentFilter(
    new[] { Intent.ActionView },
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataScheme = "https",
    DataHost = "yourdomain.com",
    DataPathPrefix = "/referral",
    AutoVerify = true)]
public class MainActivity : MauiAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        HandleIntent(Intent);
    }

    protected override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);
        HandleIntent(intent);
    }

    private void HandleIntent(Intent intent)
    {
        if (intent?.Data != null)
        {
            DeepLinkService.Instance.HandleUrl(intent.Data.ToString());
        }
    }
}

다음 위치에 호스팅하세요: https://yourdomain.com/.well-known/assetlinks.json:

[
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
      "namespace": "android_app",
      "package_name": "com.yourcompany.yourapp",
      "sha256_cert_fingerprints": [
        "YOUR_SIGNING_KEY_FINGERPRINT"
      ]
    }
  }
]

두 플랫폼이 들어온 URL을 넘겨줄 공용 서비스를 만드세요:

// Services/DeepLinkService.cs

public class DeepLinkService
{
    private static DeepLinkService _instance;
    public static DeepLinkService Instance => _instance ??= new DeepLinkService();

    private string _pendingUrl;
    private bool _isReady;

    public void HandleUrl(string urlString)
    {
        if (_isReady)
        {
            RouteUrl(urlString);
        }
        else
        {
            // App not fully initialized yet, queue the URL
            _pendingUrl = urlString;
        }
    }

    public void MarkReady()
    {
        _isReady = true;
        if (!string.IsNullOrEmpty(_pendingUrl))
        {
            RouteUrl(_pendingUrl);
            _pendingUrl = null;
        }
    }

    private void RouteUrl(string urlString)
    {
        if (!Uri.TryCreate(urlString, UriKind.Absolute, out var uri))
            return;

        var path = uri.AbsolutePath.TrimEnd('/');
        var query = System.Web.HttpUtility.ParseQueryString(uri.Query);

        MainThread.BeginInvokeOnMainThread(async () =>
        {
            await NavigateFromDeepLink(path, query);
        });
    }

    private async Task NavigateFromDeepLink(
        string path,
        System.Collections.Specialized.NameValueCollection query)
    {
        // Product page
        var productMatch = System.Text.RegularExpressions.Regex.Match(
            path, @"^/products/([^/]+)$");
        if (productMatch.Success)
        {
            var productId = productMatch.Groups[1].Value;
            await Shell.Current.GoToAsync(
                $"//products/detail?productId={productId}");
            return;
        }

        // Offer page
        var offerMatch = System.Text.RegularExpressions.Regex.Match(
            path, @"^/offers/([^/]+)$");
        if (offerMatch.Success)
        {
            var offerId = offerMatch.Groups[1].Value;
            await Shell.Current.GoToAsync(
                $"//offers/detail?offerId={offerId}");
            return;
        }

        // Referral
        var referralMatch = System.Text.RegularExpressions.Regex.Match(
            path, @"^/referral/([^/]+)$");
        if (referralMatch.Success)
        {
            var referrerId = referralMatch.Groups[1].Value;
            // Store referral, then navigate to home
            Preferences.Set("referrer_id", referrerId);
            await Shell.Current.GoToAsync("//home");
            return;
        }

        // Default
        await Shell.Current.GoToAsync("//home");
    }
}

Shell 내비게이션 설정

라우트를 등록할 파일: AppShell.xaml.cs:

public partial class AppShell : Shell
{
    public AppShell()
    {
        InitializeComponent();

        // Register detail routes for deep linking
        Routing.RegisterRoute("products/detail", typeof(ProductDetailPage));
        Routing.RegisterRoute("offers/detail", typeof(OfferDetailPage));
        Routing.RegisterRoute("referral", typeof(ReferralPage));
    }
}

AppShell.xaml

<?xml version="1.0" encoding="UTF-8" ?>
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       xmlns:pages="clr-namespace:YourApp.Pages"
       x:Class="YourApp.AppShell">

    <TabBar>
        <ShellContent Title="Home"
                      Route="home"
                      ContentTemplate="{DataTemplate pages:HomePage}" />
        <ShellContent Title="Products"
                      Route="products"
                      ContentTemplate="{DataTemplate pages:ProductsPage}" />
        <ShellContent Title="Offers"
                      Route="offers"
                      ContentTemplate="{DataTemplate pages:OffersPage}" />
    </TabBar>
</Shell>

쿼리 파라미터 처리

가능하면 QueryProperty 속성을 쓰면 페이지에서 파라미터를 받을 수 있어요:

[QueryProperty(nameof(ProductId), "productId")]
public partial class ProductDetailPage : ContentPage
{
    private string _productId;
    public string ProductId
    {
        get => _productId;
        set
        {
            _productId = value;
            LoadProduct(value);
        }
    }

    private async void LoadProduct(string productId)
    {
        if (string.IsNullOrEmpty(productId)) return;

        try
        {
            var product = await ProductService.GetByIdAsync(productId);
            BindingContext = product;
        }
        catch (Exception ex)
        {
            await DisplayAlert("Error", "Could not load product", "OK");
            await Shell.Current.GoToAsync("..");
        }
    }
}

앱 초기화

앱 초기화가 끝나면 준비됐다고 알려주세요:

// App.xaml.cs
public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        MainPage = new AppShell();
    }

    protected override void OnStart()
    {
        base.OnStart();
        // 앱이 딥 링크를 처리할 준비가 됐다고 알림
        DeepLinkService.Instance.MarkReady();
    }
}

의존성 주입을 쓰는 방법

싱글턴 패턴 대신 MAUI 내장 DI를 사용하세요:

// MauiProgram.cs
public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .ConfigureFonts(fonts =>
        {
            fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
        });

    // 딥 링크 서비스 등록
    builder.Services.AddSingleton<IDeepLinkService, DeepLinkService>();

    return builder.Build();
}
// 인터페이스
public interface IDeepLinkService
{
    void HandleUrl(string url);
    void MarkReady();
}

필요한 곳에 주입하세요:

public partial class App : Application
{
    private readonly IDeepLinkService _deepLinkService;

    public App(IDeepLinkService deepLinkService)
    {
        InitializeComponent();
        _deepLinkService = deepLinkService;
        MainPage = new AppShell();
    }

    protected override void OnStart()
    {
        base.OnStart();
        _deepLinkService.MarkReady();
    }
}

테스트

iOS 시뮬레이터

xcrun simctl openurl booted "https://yourdomain.com/products/abc123"

Android 에뮬레이터

adb shell am start -a android.intent.action.VIEW \
  -d "https://yourdomain.com/products/abc123" \
  -c android.intent.category.BROWSABLE

라우터 단위 테스트

[TestFixture]
public class DeepLinkServiceTests
{
    [Test]
    public void ParsesProductUrl()
    {
        var uri = new Uri("https://yourdomain.com/products/abc123");
        var path = uri.AbsolutePath;

        var match = Regex.Match(path, @"^/products/([^/]+)$");

        Assert.IsTrue(match.Success);
        Assert.AreEqual("abc123", match.Groups[1].Value);
    }

    [Test]
    public void ParsesQueryParameters()
    {
        var uri = new Uri("https://yourdomain.com/products/abc123?ref=email&campaign=summer");
        var query = System.Web.HttpUtility.ParseQueryString(uri.Query);

        Assert.AreEqual("email", query["ref"]);
        Assert.AreEqual("summer", query["campaign"]);
    }

    [Test]
    public void HandlesTrailingSlash()
    {
        var uri = new Uri("https://yourdomain.com/products/abc123/");
        var path = uri.AbsolutePath.TrimEnd('/');

        var match = Regex.Match(path, @"^/products/([^/]+)$");

        Assert.IsTrue(match.Success);
        Assert.AreEqual("abc123", match.Groups[1].Value);
    }
}

.NET MAUI 앱용 Tolinku

Tolinku AASA와 assetlinks.json 검증 파일을 호스팅해요. iOS Team ID, 번들 식별자, Android 패키지 이름, SHA-256 지문을 Appspace 설정에서 설정하면 Tolinku가 두 파일을 자동으로 만들어 줘요. 자세한 내용은 다음을 참고하세요: iOS 설정 가이드 와 Android 설정 가이드 를 참고하세요.

기존 Xamarin 방식은 다음을 참고하세요: Xamarin 딥 링킹: 크로스 플랫폼 설정. 처음부터 만든다면 다음을 참고하세요: 딥 링크를 처음부터 구현하는 방법.

딥 링킹 팁을 메일로 받아 보세요

일주일에 한 번만 보내요. 스팸은 없어요.

앱에 딥 링킹을 추가해 볼까요?

유니버설 링크, 앱 링크, 디퍼드 딥 링킹, 분석을 몇 분 만에 설정할 수 있어요. 무료로 시작하세요.