From 56e2ebdb8a5795c358ee1dd38ae382e24ae866cf Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Fri, 4 Oct 2024 17:48:59 -0700 Subject: [PATCH] Updated to support warm linking --- Branch-Xamarin-SDK.nuspec | 24 +++++++------- .../BranchSDK.AndroidBinding.csproj | 2 +- .../BranchSDK.iOSBinding.csproj | 2 +- BranchSDK/BranchSDK.csproj | 14 ++++---- BranchSDK/Platforms/Android/BranchAndroid.cs | 33 ++++++++++++++++--- Timber/Platforms/Android/MainActivity.cs | 18 +++++++--- Timber/Timber.csproj | 13 ++++---- 7 files changed, 70 insertions(+), 36 deletions(-) diff --git a/Branch-Xamarin-SDK.nuspec b/Branch-Xamarin-SDK.nuspec index 1e3dcd5..ecbbfae 100644 --- a/Branch-Xamarin-SDK.nuspec +++ b/Branch-Xamarin-SDK.nuspec @@ -13,14 +13,14 @@ Copyright 2020 Branch Metrics, Inc. Xamarin Branch deep linking tracking measurement iOS Android sharing referral invite analytics - + - + - + @@ -32,19 +32,19 @@ - - - + + + - - + + - - - - + + + + diff --git a/BranchSDK.AndroidBinding/BranchSDK.AndroidBinding.csproj b/BranchSDK.AndroidBinding/BranchSDK.AndroidBinding.csproj index a8fa5d2..ba96a4a 100644 --- a/BranchSDK.AndroidBinding/BranchSDK.AndroidBinding.csproj +++ b/BranchSDK.AndroidBinding/BranchSDK.AndroidBinding.csproj @@ -1,6 +1,6 @@ - net6.0-android + net8.0-android 24 enable enable diff --git a/BranchSDK.iOSBinding/BranchSDK.iOSBinding.csproj b/BranchSDK.iOSBinding/BranchSDK.iOSBinding.csproj index 7461c0f..c12dbbd 100644 --- a/BranchSDK.iOSBinding/BranchSDK.iOSBinding.csproj +++ b/BranchSDK.iOSBinding/BranchSDK.iOSBinding.csproj @@ -1,6 +1,6 @@ - net6.0-ios + net8.0-ios enable true true diff --git a/BranchSDK/BranchSDK.csproj b/BranchSDK/BranchSDK.csproj index 545da21..c93b03b 100644 --- a/BranchSDK/BranchSDK.csproj +++ b/BranchSDK/BranchSDK.csproj @@ -1,10 +1,10 @@ - net6.0;net6.0-android;net6.0-ios - $(TargetFrameworks);net6.0-windows10.0.19041.0 + net8.0;net8.0-android;net8.0-ios + $(TargetFrameworks);net8.0-windows10.0.19041.0 - + true true enable @@ -18,10 +18,10 @@ 6.5 - + false - + false @@ -29,10 +29,10 @@ - ..\BranchSDK.AndroidBinding\bin\Release\net6.0-android\BranchSDK.AndroidBinding.dll + ..\BranchSDK.AndroidBinding\bin\Release\net8.0-android\BranchSDK.AndroidBinding.dll - ..\BranchSDK.iOSBinding\bin\Release\net6.0-ios\BranchSDK.iOSBinding.dll + ..\BranchSDK.iOSBinding\bin\Release\net8.0-ios\BranchSDK.iOSBinding.dll diff --git a/BranchSDK/Platforms/Android/BranchAndroid.cs b/BranchSDK/Platforms/Android/BranchAndroid.cs index 4d8d511..dd93e10 100644 --- a/BranchSDK/Platforms/Android/BranchAndroid.cs +++ b/BranchSDK/Platforms/Android/BranchAndroid.cs @@ -88,13 +88,12 @@ public static void Init(Android.App.Application app, String branchKey, IBranchSe instance.branchKey = branchKey; AndroidNativeBranch.RegisterPlugin(pluginName, pluginVersion); + if (EnableLogging) { AndroidNativeBranch.EnableLogging(BranchLogger.BranchLogLevel.Verbose); } - AndroidNativeBranch.EnableLogging(BranchLogger.BranchLogLevel.Verbose); - instance.lifeCycleHandler = new BranchAndroidLifeCycleHandler(callback); app.RegisterActivityLifecycleCallbacks(instance.lifeCycleHandler); @@ -122,13 +121,12 @@ public static void Init(Android.App.Application app, String branchKey, IBranchBU instance.branchKey = branchKey; AndroidNativeBranch.RegisterPlugin(pluginName, pluginVersion); + if (EnableLogging) { AndroidNativeBranch.EnableLogging(BranchLogger.BranchLogLevel.Verbose); } - AndroidNativeBranch.EnableLogging(BranchLogger.BranchLogLevel.Verbose); - instance.lifeCycleHandler = new BranchAndroidLifeCycleHandler(callback); app.RegisterActivityLifecycleCallbacks(instance.lifeCycleHandler); @@ -160,6 +158,33 @@ public override void InitSession(IBranchBUOSessionInterface callback) .Init(); } + public void ReInitSession(Intent intent, IBranchSessionInterface callback, Activity activity) + { + callbacksList.Clear(); + BranchSessionListener obj = new BranchSessionListener(callback); + callbacksList.Add(obj as Object); + + activity.Intent = intent; + + AndroidNativeBranch.SessionBuilder(activity) + .WithCallback(obj) + .WithData(intent.Data) + .ReInit(); + } + + public void ReInitSession(Intent intent, IBranchBUOSessionInterface callback, Activity activity) + { + callbacksList.Clear(); + BranchBUOSessionListener obj = new BranchBUOSessionListener(callback); + callbacksList.Add(obj as Object); + + activity.Intent = intent; + + AndroidNativeBranch.SessionBuilder(activity) + .WithCallback(obj) + .WithData(intent.Data) + .ReInit(); + } public override void NotifyNativeInit() { diff --git a/Timber/Platforms/Android/MainActivity.cs b/Timber/Platforms/Android/MainActivity.cs index aa702e5..bcfe220 100644 --- a/Timber/Platforms/Android/MainActivity.cs +++ b/Timber/Platforms/Android/MainActivity.cs @@ -25,18 +25,26 @@ namespace Timber; * Implement IBranchSessionInterface to get Branch Payloads * */ -[Activity(Name = "io.branch.timber.MainActivity", Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] +[Activity(Name = "io.branch.timber.MainActivity", Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTask, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] public class MainActivity : MauiAppCompatActivity, IBranchSessionInterface { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); + LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnCreate still"); BranchAndroid.Init(this, "key_live_nf8w3l1WBpzWdlC00KsLNdmbuEccK6Yr", this); } + protected override void OnNewIntent(Intent intent) + { + base.OnNewIntent(intent); + LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnNewIntent"); + BranchAndroid.getInstance().ReInitSession(intent, this, this); + } + public void InitSessionComplete(Dictionary data) { - LogMessage("InitSessionComplete: "); + LogMessage("BRANCHSDK .NET MAUI: InitSessionComplete: "); foreach (var key in data.Keys) { LogMessage(key + " : " + data[key].ToString()); @@ -45,9 +53,9 @@ public void InitSessionComplete(Dictionary data) public void SessionRequestError(BranchError error) { - LogMessage("SessionRequestError: "); - LogMessage("Error Message: " + error.ErrorMessage); - LogMessage("Error Code: " + error.ErrorCode); + LogMessage("BRANCHSDK .NET MAUI: SessionRequestError: "); + LogMessage("BRANCHSDK .NET MAUI: Error Message: " + error.ErrorMessage); + LogMessage("BRANCHSDK .NET MAUI: Error Code: " + error.ErrorCode); } void LogMessage(string message) diff --git a/Timber/Timber.csproj b/Timber/Timber.csproj index 525015c..632df06 100644 --- a/Timber/Timber.csproj +++ b/Timber/Timber.csproj @@ -1,10 +1,11 @@  - net7.0-android;net7.0-ios - $(TargetFrameworks);net7.0-windows10.0.19041.0 + net8.0-android;net8.0-ios + $(TargetFrameworks);net8.0-windows10.0.19041.0 + - + Exe Timber true @@ -30,7 +31,7 @@ 6.5 - + false Automatic iPhone Developer @@ -39,7 +40,7 @@ 4 - + false @@ -64,7 +65,7 @@ - +