SFMC.MarketingCloudSDK.MAUI 1.0.3

dotnet add package SFMC.MarketingCloudSDK.MAUI --version 1.0.3
                    
NuGet\Install-Package SFMC.MarketingCloudSDK.MAUI -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SFMC.MarketingCloudSDK.MAUI" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SFMC.MarketingCloudSDK.MAUI" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="SFMC.MarketingCloudSDK.MAUI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SFMC.MarketingCloudSDK.MAUI --version 1.0.3
                    
#r "nuget: SFMC.MarketingCloudSDK.MAUI, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SFMC.MarketingCloudSDK.MAUI@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SFMC.MarketingCloudSDK.MAUI&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=SFMC.MarketingCloudSDK.MAUI&version=1.0.3
                    
Install as a Cake Tool

πŸš€ Salesforce Marketing Cloud SDK for .NET MAUI

This repository provides a .NET MAUI binding for integrating the Salesforce Marketing Cloud (SFMC) SDK into iOS and Android applications.

πŸ“Œ Available API Endpoints & Roadmap

This section outlines the currently available API endpoints in this version of the SFMC.MarketingCloudSDK.MAUI package and provides insight into the upcoming features planned for future releases.

βΈ»

βœ… Available API Endpoints (Current Version)

The following API endpoints are implemented and ready for use in this version:

πŸ”Ή ANDROID
Endpoint Description
InitializeSDK(activity,notificationDrawable,mcApplicationId,mcAccessToken,fcmSenderId,marketingCloudUrl,inboxEnabled,analyticsEnabled,isDebug) Initializes the Salesforce Marketing Cloud SDK.
TogglePushPermission(granted) Enables or disables push notifications based on user permission.
SetContactKey(contactKey) Sets the contact key for the current user.
setProfileAttribute(key,value) Sets a custom profile attribute for the user.
πŸ”Ή iOS
Endpoint Description
InitializeSDKWithAppId(appId, accessToken, appEndpointURL, mid) Initializes the Salesforce Marketing Cloud SDK.
SetupMobilePush() Enables or disables push notifications based on user permission.
SetContactKeyWithContactKey(contactKey) Sets the contact key for the current user.
SetProfileAttribute(key,value) Sets a custom profile attribute for the user.
RegisterDeviceToken(token) Sets a custom profile attribute for the user.

πŸ”œ Upcoming Features (Next Versions)

In the next releases, we plan to expand the API capabilities with the following features:

πŸš€ Planned Enhancements

Feature Group Expected Version Status
Inbox Message Management v1.1.0 πŸ”„ In Progress
General SDK Information v1.1.1 πŸ†• Planned
User & Device Management v1.1.2 πŸ†• Planned
Attribute Management v1.1.3 πŸ†• Planned
Push Notification Management v1.1.4 πŸ†• Planned

πŸ“Œ Prerequisites

1️⃣ Generate an Authentication Certificate

Before integrating the SDK, follow the Salesforce MobilePush guide to create the required APNs authentication key:
πŸ”— Salesforce MobilePush Prerequisites

2️⃣ Install Required NuGet Packages

Run the following commands to install the necessary dependencies:

dotnet add package Microsoft.Extensions.Configuration.Json
dotnet add package Microsoft.Extensions.Configuration.Binder

Add SFMC SDK

dotnet add package SFMC.MarketingCloudSDK.MAUI

3️⃣ Configure SFMC Settings

Create a configuration file to dynamically load Marketing Cloud credentials in Config/MarketingCloudConfig.cs.

using Microsoft.Extensions.Configuration;

public class MarketingCloudConfig
{
    public string AppId { get; set; }
    public string AccessToken { get; set; }
    public string AppEndpointURL { get; set; }
    public string Mid { get; set; }
    public string SenderId { get; set; }

    public static MarketingCloudConfig Load(IConfiguration configuration)
    {
#if DEBUG
        string environment = "Debug";
#else
        string environment = "Production";
#endif
        return configuration.GetRequiredSection($"MarketingCloudConfig:{environment}").Get<MarketingCloudConfig>()
            ?? throw new Exception("❌ Marketing Cloud configuration is missing.");
    }
}

βœ… This allows for easy environment-based configuration (Debug vs Production).

4️⃣ Add appsettings.json for Configuration

Add Salesforce Marketing Cloud credentials inside Resources/Raw/appsettings.json.

{
  "MarketingCloudConfig": {
    "Debug": {
      "AppId": "",
      "AccessToken": "",
      "AppEndpointURL": "",
      "Mid": "",
      "SenderId": ""
    },
    "Production": {
      "AppId": "",
      "AccessToken": "",
      "AppEndpointURL": "",
      "Mid": "",
      "SenderId": ""
    }
  }
}

βœ… This enables different configurations for Development and Production.

5️⃣ Register the Marketing Cloud SDK in MauiProgram.cs

Modify MauiProgram.cs to initialize the Marketing Cloud SDK during app startup.

πŸ“Œ Add the registration method
.RegisterMarketingCloudSDK();
πŸ“Œ Implement the RegisterMarketingCloudSDK method

Inside MauiProgram.cs, add the following extension method:

#region MarketingCloudSDK

private static MauiAppBuilder RegisterMarketingCloudSDK(this MauiAppBuilder mauiAppBuilder)
{
	try
	{
		mauiAppBuilder.ConfigureLifecycleEvents(events =>
		{
			var config = MarketingCloudConfig.Load(mauiAppBuilder.Configuration);
#if IOS
			events.AddiOS(iOS => iOS.WillFinishLaunching((_, __) =>
		    {
			    MarketingCloudiOS.DotnetMarketingCloud.InitializeSDKWithAppId(
				    config.AppId,
				    config.AccessToken,
				    config.AppEndpointURL,
				    config.Mid
			    );

			    return true;
		    }));
#elif ANDROID
			events.AddAndroid(android => android.OnCreate(async (activity, bundle) =>
			{
				var token = await CrossFirebaseCloudMessaging.Current.GetTokenAsync();

				MarketingCloudAndroid.DotnetMarketingCloud.InitializeSDK(
					activity,
					Resource.Drawable.ic_stat_logo,
					config.AppId,
					config.AccessToken,
					config.SenderId,
					config.AppEndpointURL,
					true, // Enable Inbox
					true, // Enable Analytics
					true // Enable Debug Mode
				);
			}));
#endif
		});

	}
	catch (Exception ex)
	{
		Debug.WriteLine($"Error trying to init RegisterMauiMobilePushSDK: {ex.Message}");
	}

	return mauiAppBuilder;
}
#endregion

βœ… This ensures the SDK is initialized, the user is registered, and profile attributes are set at app startup.


ο£Ώ iOS Implementation

πŸ”Ή Step 1: Update AppDelegate.cs

Modify your AppDelegate.cs to handle push notification registration and error handling.

[Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")]
public void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
    Console.WriteLine("βœ… Successfully registered for push notifications");

    // Pass device token to SFMC via Swift binding
    MarketingCloudiOS.DotnetMarketingCloud.RegisterDeviceToken(deviceToken);
}

[Export("application:didFailToRegisterForRemoteNotificationsWithError:")]
public void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
    Debug.WriteLine($"❌ Push registration failed: {error.Description}");
}

[Export("application:didReceiveRemoteNotification:fetchCompletionHandler:")]
public void DidReceiveRemoteNotification(UIApplication application, NSDictionary notification, Action<UIBackgroundFetchResult> completionHandler)
{
    Console.WriteLine("πŸ“© Received remote notification");

    // Handle the notification when the app is in the foreground
    completionHandler(UIBackgroundFetchResult.NewData);
}

βœ… This ensures that iOS handles push notifications correctly and registers the device with SFMC.

πŸ”Ή Step 2: Add this where you will ask for push permissions

#if IOS
					MarketingCloudiOS.DotnetMarketingCloud.SetupMobilePush();
#endif

βœ… This ensures that iOS prompt for permissions.


πŸ€– Android Implementation

⚠️ Important: Firebase Cloud Messaging (FCM) Integration Required!

Before integrating Salesforce Marketing Cloud SDK (SFMC) into your Android App, you must first integrate Firebase Cloud Messaging (FCM) into your project. SFMC relies on Firebase for push notifications, and FCM must be initialized before SFMC SDK to avoid issues with token retrieval.

πŸ”Ή Step 1: Update MainActivity.cs

public class MainActivity : MauiAppCompatActivity
	{
		protected override void OnCreate(Bundle savedInstanceState)
		{
			base.OnCreate(savedInstanceState);

			CreateNotificationChannelIfNeeded();
		}

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

		private void CreateNotificationChannelIfNeeded()
		{
			if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
			{
				CreateNotificationChannel();
			}
		}

		private void CreateNotificationChannel()
		{
			try
			{
				var channelId = $"{PackageName}.general";
				var notificationManager = (NotificationManager)GetSystemService(NotificationService);
				var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
				notificationManager.CreateNotificationChannel(channel);

			}
			catch (Exception ex)
			{
				System.Diagnostics.Debug.WriteLine($"Error trying to create notification channel\n{ex}");
			}
		}

		public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
		{
			Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
			base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
		}
	}

πŸ”Ή Step 2: Add this where you will ask for push permissions

#if ANDROID
				MarketingCloudAndroid.DotnetMarketingCloud.TogglePushPermission(true/false);
#endif

βœ… This ensures that Android prompt for permissions.

Product Compatible and additional computed target framework versions.
.NET net8.0-android32.0 is compatible.  net8.0-ios18.0 is compatible.  net9.0-android was computed.  net9.0-ios was computed.  net10.0-android was computed.  net10.0-ios was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 284 3/20/2025
1.0.2 170 3/20/2025