Skip to content

Commit

Permalink
add deeplinking
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Nov 24, 2023
1 parent 23c03a8 commit 54c3831
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 7 deletions.
9 changes: 8 additions & 1 deletion ProjectTemplates/ShinyApp/.template.config/ide.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,14 @@
"text": "Setup MAUI Essentials - App Actions"
},
"isVisible": true
},
},
{
"id": "deeplinks",
"name": {
"text": "Setup Deep Linking Support"
},
"isVisible": true
},
{
"id": "communitytoolkit",
"name": {
Expand Down
15 changes: 13 additions & 2 deletions ProjectTemplates/ShinyApp/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@
"description": "Sets all up all the necessary boilerplate for the MAUI App Actions",
"displayName": "Setup MAUI Essentials - App Actions"
},
"deeplinks":{
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Sets up initial deep link support",
"displayName": "Setup Deep Linking Support"
},
"communitytoolkit":{
"type": "parameter",
"datatype": "bool",
Expand Down Expand Up @@ -615,15 +622,19 @@
{
"condition": "(notifications == false)",
"exclude": "Delegates/MyLocalNotificationDelegate.cs"
},
},
{
"condition": "(beacons == false)",
"exclude": "Delegates/MyBeaconMonitoringDelegate.cs"
},
{
"condition": "(appactions == false)",
"exclude": "Delegates/AppActionDelegate.cs"
},
},
{
"condition": "(deeplinks == false)",
"exclude": "Delegates/DeepLinkDelegate.cs"
},
{
"condition": "(sqlite == false)",
"exclude": "Services/MySqliteConnection.cs"
Expand Down
61 changes: 61 additions & 0 deletions ProjectTemplates/ShinyApp/Delegates/DeepLinkDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Shiny.Hosting;

#if APPLE
using UIKit;
#elif ANDROID
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
#endif

namespace ShinyApp.Delegates;


public partial class DeepLinkDelegate
{
//https://github.com/Redth/MAUI.AppLinks.Sample/tree/main

public void Handle(string uri)
{

}
}

#if APPLE
public partial class DeepLinkDelegate : IosLifecycle.IContinueActivity
{
// ios.FinishedLaunching((app, data)
// => HandleAppLink(app.UserActivity));

// ios.ContinueUserActivity((app, userActivity, handler)
// => HandleAppLink(userActivity));

// if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsMacCatalystVersionAtLeast(13))
// {
// ios.SceneWillConnect((scene, sceneSession, sceneConnectionOptions)
// => HandleAppLink(sceneConnectionOptions.UserActivities.ToArray()
// .FirstOrDefault(a => a.ActivityType == NSUserActivityType.BrowsingWeb)));

// ios.SceneContinueUserActivity((scene, userActivity)
// => HandleAppLink(userActivity));
// }

public bool Handle(NSUserActivity activity, UIApplicationRestorationHandler completionHandler)
{
return false;
}
}
#elif ANDROID
public partial class DeepLinkDelegate : IAndroidLifecycle.IOnActivityOnCreate
{
public void ActivityOnCreate(Activity activity, Bundle? savedInstanceState)
{
var action = activity.Intent?.Action;
var data = activity.Intent?.Data?.ToString();

if (action == Intent.ActionView && data != null)
this.Handle(data);
}
}
#endif
5 changes: 4 additions & 1 deletion ProjectTemplates/ShinyApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ static MauiAppBuilder RegisterInfrastructure(this MauiAppBuilder builder)
s.AddSingleton(CalendarStore.Default);
#endif
#if appaction
s.AddSingleton<AppActionDelegate>();
s.AddSingleton<ShinyApp.Delegates.AppActionDelegate>();
#endif
#if (deeplink)
s.AddShinyService<ShinyApp.Delegates.DeepLinkDelegate>();
#endif
#if (authservice)
#if (usemsal)
Expand Down
15 changes: 12 additions & 3 deletions ProjectTemplates/ShinyApp/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace ShinyApp;
[Activity(
Theme = "@style/Maui.SplashTheme",
MainLauncher = true,
#if (deeplink)
Exported = true,
#endif
ConfigurationChanges =
ConfigChanges.ScreenSize |
ConfigChanges.Orientation |
Expand All @@ -23,8 +26,14 @@ namespace ShinyApp;
ConfigChanges.Density
)]
[IntentFilter(
#if (deeplink)
AutoVerify = true,
DataScheme = "https",
DataHost = "{DEEPLINK_HOST}",
#endif
new[] {
Platform.Intent.ActionAppAction
Platform.Intent.ActionAppAction,
Intent.ActionView
#if (usepush)
, ShinyPushIntents.NotificationClickAction
#endif
Expand All @@ -33,7 +42,8 @@ namespace ShinyApp;
#endif
},
Categories = new[] {
global::Android.Content.Intent.CategoryDefault
global::Android.Content.Intent.CategoryDefault,
global::Android.Content.Intent.CategoryBrowsable
}
)]
public class MainActivity : MauiAppCompatActivity
Expand All @@ -55,7 +65,6 @@ protected override void OnCreate(Bundle? savedInstanceState)
//+:cnd:noEmit
#endif
#if (usemsal)
// TODO: this should move to DI section
/// <summary>
/// This is a callback to continue with the broker base authentication
/// Info abour redirect URI: https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-client-application-configuration#redirect-uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@
<key>aps-environment</key>
<string>development</string>
<!--#endif-->
<!--#if (deeplinks)-->
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:{DEEPLINK_HOST}</string>
</array>
<!--#endif-->
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@
<key>aps-environment</key>
<string>production</string>
<!--#endif-->
<!--#if (deeplinks)-->
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:{DEEPLINK_HOST}</string>
</array>
<!--#endif-->
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,11 @@
<key>aps-environment</key>
<string>development</string>
<!--#endif-->
<!--#if (deeplinks)-->
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:{DEEPLINK_HOST}</string>
</array>
<!--#endif-->
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,11 @@
<key>aps-environment</key>
<string>production</string>
<!--#endif-->
<!--#if (deeplinks)-->
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:{DEEPLINK_HOST}</string>
</array>
<!--#endif-->
</dict>
</plist>

0 comments on commit 54c3831

Please sign in to comment.