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
<PackageReference Include="SFMC.MarketingCloudSDK.MAUI" Version="1.0.3" />
<PackageVersion Include="SFMC.MarketingCloudSDK.MAUI" Version="1.0.3" />
<PackageReference Include="SFMC.MarketingCloudSDK.MAUI" />
paket add SFMC.MarketingCloudSDK.MAUI --version 1.0.3
#r "nuget: SFMC.MarketingCloudSDK.MAUI, 1.0.3"
#:package SFMC.MarketingCloudSDK.MAUI@1.0.3
#addin nuget:?package=SFMC.MarketingCloudSDK.MAUI&version=1.0.3
#tool nuget:?package=SFMC.MarketingCloudSDK.MAUI&version=1.0.3
π 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 | Versions 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. |
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.