I am trying to create some functionality when a users links into the app. I have created the apple-app-site-association file on the server. It is correctly recognized as an app link and opens my app. The issue is the OnAppLinkRequestReceived event doesn't seem to get triggered.
In my App.xaml.cs:
public App()
{
InitializeComponent();
MainPage = new AppShell();
#if IOS
(Application.Current as IApplicationController)?.SetAppIndexingProvider(new Microsoft.Maui.Controls.Compatibility.Platform.iOS.IOSAppIndexingProvider());
#endif
try
{
var entry = new AppLinkEntry
{
Title = "Find Shop",
Description = "Find Shop Deep Link",
AppLinkUri = new Uri(GlobalVariables.FindShopDeepLink, UriKind.RelativeOrAbsolute),
IsLinkActive = true
};
entry.KeyValues.Add("contentType", "id");
entry.KeyValues.Add("appName", "PopUp Shop");
entry.KeyValues.Add("companyName", "Cefworx, LLC");
Application.Current.AppLinks.RegisterLink(entry);
}
catch (Exception ex)
{
Crashes.TrackError(ex);
Crashes.TrackError(new Exception("Deeplink failed."));
}
}
protected async override void OnAppLinkRequestReceived(Uri uri)
{
await Current.MainPage.DisplayAlert("AppLink", "You are linking!", "OK");
}
In my Maui.Program:
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiCompatibility()
.UseMauiApp<App>(
.UseMauiCommunityToolkit();
.....
}
From this link: https://github.com/dotnet/maui/issues/14671
iOS: Add to Platform/iOS/AppDelegate.cs
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
{
CheckForAppLink(userActivity);
return true;
}
void CheckForAppLink(NSUserActivity userActivity)
{
var strLink = string.Empty;
switch (userActivity.ActivityType)
{
case "NSUserActivityTypeBrowsingWeb":
strLink = userActivity.WebPageUrl.AbsoluteString;
break;
case "com.apple.corespotlightitem":
if (userActivity.UserInfo.ContainsKey(CSSearchableItem.ActivityIdentifier))
strLink = userActivity.UserInfo.ObjectForKey(CSSearchableItem.ActivityIdentifier).ToString();
break;
default:
if (userActivity.UserInfo.ContainsKey(new NSString("link")))
strLink = userActivity.UserInfo[new NSString("link")].ToString();
break;
}
if (!string.IsNullOrEmpty(strLink))
App.Current.SendOnAppLinkRequestReceived(new Uri(strLink));
}
Android: Add to "Platform/Android/MainActivity.cs"
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
string action = intent.Action;
string strLink = intent.DataString;
if (Intent.ActionView != action || string.IsNullOrWhiteSpace(strLink))
return;
var link = new Uri(strLink);
App.Current.SendOnAppLinkRequestReceived(link);
}