Apps Xamarin e .NET MAUI compartilham a lógica de negócio em C# entre as plataformas, mas precisam de configuração específica de cada plataforma para deep linking. Os arquivos de verificação (AASA, assetlinks.json), os entitlements e os filtros de Intent são responsabilidades nativas. A lógica de roteamento de URLs pode ser compartilhada.
Para deep linking com Kotlin Multiplatform, veja Deep links com Kotlin Multiplatform. Para uma visão geral multiplataforma, veja o guia de deep linking multiplataforma para 2026.
.NET MAUI Setup (Recommended)
.NET MAUI é o sucessor do Xamarin.Forms. Se você está começando um projeto novo, use o MAUI.
Configuração no iOS
1. Adicione os Associated Domains
No seu projeto MAUI, adicione o entitlement em 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>
2. Trate os Universal Links no AppDelegate
Em Platforms/iOS/AppDelegate.cs:
[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();
DeepLinkHandler.HandleUrl(url);
return true;
}
return false;
}
Configuração no Android
1. Adicione os Intent Filters
Em 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" />
</intent-filter>
</activity>
Ou use o atributo IntentFilter atributo na sua MainActivity:
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, Exported = true)]
[IntentFilter(
new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "https",
DataHost = "yourdomain.com",
DataPathPrefix = "/products",
AutoVerify = true)]
public class MainActivity : MauiAppCompatActivity
{
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
if (intent?.Data != null)
{
DeepLinkHandler.HandleUrl(intent.Data.ToString());
}
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
if (Intent?.Data != null)
{
DeepLinkHandler.HandleUrl(Intent.Data.ToString());
}
}
}
Lógica de roteamento compartilhada
Roteador de deep links (código compartilhado)
Crie um handler de deep links compartilhado que funcione nas duas plataformas:
// DeepLinkHandler.cs (projeto compartilhado)
public static class DeepLinkHandler
{
public static void HandleUrl(string urlString)
{
if (!Uri.TryCreate(urlString, UriKind.Absolute, out var uri))
return;
var path = uri.AbsolutePath;
var query = System.Web.HttpUtility.ParseQueryString(uri.Query);
// Verifica as rotas
if (TryMatch(path, "/products/{0}", out var productId))
{
NavigateToProduct(productId, query);
return;
}
if (TryMatch(path, "/offers/{0}", out var offerId))
{
NavigateToOffer(offerId, query);
return;
}
if (TryMatch(path, "/referral/{0}", out var referrerId))
{
NavigateToReferral(referrerId, query);
return;
}
// Padrão
NavigateToHome();
}
private static bool TryMatch(string path, string pattern, out string param)
{
param = null;
var prefix = pattern.Replace("{0}", "");
if (!path.StartsWith(prefix)) return false;
param = path.Substring(prefix.Length).TrimEnd('/');
return !string.IsNullOrEmpty(param);
}
private static async void NavigateToProduct(string productId, NameValueCollection query)
{
await Shell.Current.GoToAsync($"//products/{productId}");
}
private static async void NavigateToOffer(string offerId, NameValueCollection query)
{
await Shell.Current.GoToAsync($"//offers/{offerId}");
}
private static async void NavigateToReferral(string referrerId, NameValueCollection query)
{
await Shell.Current.GoToAsync($"//referral/{referrerId}");
}
private static async void NavigateToHome()
{
await Shell.Current.GoToAsync("//home");
}
}
Com navegação Shell
O Shell do .NET MAUI oferece registro de rotas integrado:
// AppShell.xaml.cs
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
// Registra as rotas para deep linking
Routing.RegisterRoute("products", typeof(ProductPage));
Routing.RegisterRoute("offers", typeof(OfferPage));
Routing.RegisterRoute("referral", typeof(ReferralPage));
}
}
Tratando query parameters
// ProductPage.xaml.cs
[QueryProperty(nameof(ProductId), "productId")]
[QueryProperty(nameof(Source), "source")]
public partial class ProductPage : ContentPage
{
public string ProductId { get; set; }
public string Source { get; set; }
protected override void OnAppearing()
{
base.OnAppearing();
LoadProduct(ProductId);
// Registra a atribuição do link
if (!string.IsNullOrEmpty(Source))
{
Analytics.TrackDeepLink(Source, $"/products/{ProductId}");
}
}
}
Xamarin.Forms (legado)
Se você ainda usa Xamarin.Forms (fim do suporte: maio de 2024, o suporte estendido varia), a abordagem é parecida, mas usa APIs específicas do Xamarin.
iOS (Xamarin.iOS)
// AppDelegate.cs
public override bool ContinueUserActivity(
UIApplication application,
NSUserActivity userActivity,
UIApplicationRestorationHandler completionHandler)
{
if (userActivity.WebPageUrl != null)
{
DeepLinkHandler.HandleUrl(userActivity.WebPageUrl.ToString());
return true;
}
return false;
}
Android (Xamarin.Android)
[Activity(MainLauncher = true)]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "https",
DataHost = "yourdomain.com",
AutoVerify = true)]
public class MainActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
if (Intent?.Data != null)
{
DeepLinkHandler.HandleUrl(Intent.Data.ToString());
}
}
}
Testes
Simulador do iOS
xcrun simctl openurl booted "https://yourdomain.com/products/abc123"
Emulador do Android
adb shell am start -a android.intent.action.VIEW \
-d "https://yourdomain.com/products/abc123" \
-c android.intent.category.BROWSABLE
Testes unitários do roteador
[Test]
public void HandleUrl_ProductLink_NavigatesToProduct()
{
var url = "https://yourdomain.com/products/abc123?ref=email";
// Testa se a lógica de roteamento interpreta a URL corretamente
var result = DeepLinkRouter.Parse(url);
Assert.AreEqual("ProductPage", result.Screen);
Assert.AreEqual("abc123", result.Params["productId"]);
Assert.AreEqual("email", result.Query["ref"]);
}
Tolinku para apps .NET
Tolinku hospeda os arquivos AASA e o assetlinks.json, trata deferred deep linking e oferece analytics. Veja o documentação de deep linking para os detalhes de integração.
Para implementar do zero, veja como implementar deep links do zero. Para o guia completo, veja guia de deep linking multiplataforma para 2026.
Receba dicas de deep linking no seu e-mail
Um e-mail por semana. Sem spam.