MarketingCloudSDK.Net
8.2.0.8
dotnet add package MarketingCloudSDK.Net --version 8.2.0.8
NuGet\Install-Package MarketingCloudSDK.Net -Version 8.2.0.8
<PackageReference Include="MarketingCloudSDK.Net" Version="8.2.0.8" />
paket add MarketingCloudSDK.Net --version 8.2.0.8
#r "nuget: MarketingCloudSDK.Net, 8.2.0.8"
// Install MarketingCloudSDK.Net as a Cake Addin #addin nuget:?package=MarketingCloudSDK.Net&version=8.2.0.8 // Install MarketingCloudSDK.Net as a Cake Tool #tool nuget:?package=MarketingCloudSDK.Net&version=8.2.0.8
MarketingCloudSDK.Net and SFMCSDK
.Net 7 and .Net 8 support, Android and iOS
WIKI and API:
- ** Android SDK Online Reference**: Salesforce Marketing Cloud SDK
- ** iOS SDK Online Reference**: Salesforce Marketing Cloud SDK
Android Issues
to able run and compile and avoid issue
Error JAVAC0000: error: cannot access * com.salesforce.marketingcloud.* bad class file: obj/Debug/net7.0-android/lp/179/jl/classes.jar(/com/salesforce/marketingcloud/*.class) class file has wrong version 61.0, should be 55.0 Please remove or make sure it appears in the correct subdirectory of the classpath. Directory 'obj/Debug/net7.0-android/lp/179' is from 'marketingcloudsdk.aar'. (JAVAC0000) (*) javac
install JDK 17 and select it path in xamarin studio settings
fix r8 issues:
Compilation failed java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
download latest R8 jar file
and add <AndroidR8JarPath>Platforms/Android/r8-8.2.42.jar</AndroidR8JarPath> to your csproj file inside <PropertyGroup></PropertyGroup>
Initialize iOS
AppDelegate.cs: `[Register("AppDelegate")] public class AppDelegate : MauiUIApplicationDelegate { protected override MauiApp CreateMauiApp() ⇒ MauiProgram.CreateMauiApp();
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
SfmcManager.ConfigurePlatformSdk();
return base.FinishedLaunching(application, launchOptions);
}
}
public static void ConfigurePlatformSdk() { // Silence Keychain Crash: // If a device is setup with FaceId or Passcode based authentication, // and if an application (with MarketingCloudSDK integrated) // accesses the Keychain when the device is in a locked state, a fatal // exception is thrown. The SDK cannot access these files due to the iOS Data // Protection mode. // https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/trouble/trouble-Keychain-crash.html
SFMCSdk.SetKeychainAccessErrorsAreFatalWithErrorsAreFatal(errorsAreFatal: false);
var appId = "";
var accessToken = "";
var serverUrl = "";
var mid = "";
var pushConfig = new PushConfigBuilder(appId)
.SetAccessToken(accessToken)
.SetMarketingCloudServerUrl(new NSUrl(serverUrl))
.SetMid(mid)
.SetInboxEnabled(false)
.SetLocationEnabled(false)
.SetAnalyticsEnabled(true)
.SetDelayRegistrationUntilContactKeyIsSet(true)
.Build();
SFMCSdk.SetLoggerWithLogLevel(SFMCSdkLogLevel.Debug, new SFMCSdkLogOutputter());
SFMCSdk.Mp.SetDebugLoggingEnabled(true);
var configuration = new SFMCSdkConfigBuilder()
.SetPushWithConfig(pushConfig, r => OnSdkInitialized(r))
.Build();
SFMCSdk.InitializeSdk(configuration);
}
static void OnSdkInitialized(SFMCSdkOperationResult result)
{
//TODO: YAYA
}
public class Logger : SFMCSdkLogOutputter
{
public override void OutWithLevel(SFMCSdkLogLevel level, string subsystem, SFMCSdkLoggerCategory category, string message)
{
Debug.WriteLine($"SFMC - Logger - OutWithLevel: {level} | {subsystem} | {category} | {message}");
//base.OutWithLevel(level, subsystem, category, message);
}
}`
Initialize Android
MainApplication.cs: `[Application] public class MainApplication : MauiApplication { public MainApplication(IntPtr handle, JniHandleOwnership ownership) : base(handle, ownership) { }
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
public override void OnCreate()
{
ConfigurePlatformSdk(this as Android.Content.Context);
base.OnCreate();
}
}
public static void ConfigurePlatformSdk(Android.Content.Context context) { var appId = ""; var accessToken = ""; var serverUrl = ""; var mid = "";
// Initialize logging _before_ initializing the SDK to avoid losing valuable debugging information.
SFMCSdk.SetLogging(LogLevel.Debug, new ILogListener.AndroidLogger());
MarketingCloudSdk.LogLevel = MCLogListener.Verbose;
MarketingCloudSdk.SetLogListener(new IMCLogListener.AndroidLogListener());
var mbuilder = MarketingCloudConfig.InvokeBuilder();
mbuilder = mbuilder.SetApplicationId(appId);
mbuilder = mbuilder.SetAccessToken(accessToken);
mbuilder = mbuilder.SetMarketingCloudServerUrl(serverUrl);
//TODO: get this one, it is from documentation https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/sdk-implementation/implement-sdk-google.html
// but I have no Idea about the value of it
//mbuilder = mbuilder.SetSenderId("<firebase sender id>");
mbuilder = mbuilder.SetMid(mid);
//required!!! will crash if no options
mbuilder = mbuilder.SetNotificationCustomizationOptions(NotificationCustomizationOptions.Create(Android.Resource.Drawable.GalleryThumb));
var sfBuilder = new SFMCSdkModuleConfig.Builder();
sfBuilder.PushModuleConfig = mbuilder.Build(context);
SFMCSdk.Configure(context, sfBuilder.Build(), new Function1Impl<SFMCSdkInitializationStatus>((result) => { var stat = result.Status == SFMCSdkInitializationStatus.InterfaceConsts.Success ? "Success" : "Failure"; Debug.WriteLine($"SFMC - OnSdkInitialized: {stat}"); }));
}
public class Function1Impl<T> : Java.Lang.Object, IFunction1 where T : Java.Lang.Object
{
private readonly Action<T> OnInvoked;
public Function1Impl(Action<T> onInvoked)
{
this.OnInvoked = onInvoked;
}
public Java.Lang.Object Invoke(Java.Lang.Object objParameter)
{
try
{
T parameter = (T)objParameter;
OnInvoked?.Invoke(parameter);
return null;
}
catch (System.Exception ex)
{
// Exception handling, if needed
}
return null;
}
}`
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-android34.0 is compatible. net8.0-ios17.2 is compatible. |
-
net8.0-android34.0
- SFMCSDK.Net.Android (>= 1.0.5.8)
- Xamarin.AndroidX.Collection.Ktx (>= 1.4.3.1)
- Xamarin.Firebase.Messaging (>= 124.0.1)
-
net8.0-ios17.2
- SFMCSDK.Net.iOS (>= 1.1.3.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.