To install the C# SDK:

1

Confirm that you meet the minimum requirements. (Prerequisites)

2

Install the Ditto SDK. (Installing Dependencies)

3

Set up your app permissions. (Configuring Permissions)

4

Add Ditto to your app. (Initializing Ditto)

Prerequisites

Following are the minimum requirements that must be met before attempting to install Ditto:

Installing Dependencies

Using either a compatible package manager, the .NET CLI, or by adding a reference to the package: CSProj.xml file, install the Ditto SDK by doing any of the following:

If using a package manager other than NuGet, the official package manager for .NET, the command syntax to install Ditto may differ from the following snippet. For more information, see the official Nuget documentation > Ditto .NET Standard.

For the official .NET standard for Ditto, see the official NuGet reference at Packages > Ditto.

Configuring Permissions

To set up your environment for your target platform:

// For apps targeting iOS; for example, MAUI, once you’ve added the Ditto package dependency, // configure permissions and ensure your app continues syncing while running in the background, // including when the end-user device is locked, by enabling background modes.

1

Open the Info.Plist file for your project.

2

Add the following key-value pairs, and then, if desired, modify each string value:

XML
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Uses Bluetooth to connect and sync with nearby devices</string>
<key>NSLocalNetworkUsageDescription</key>
<string>Uses WiFi to connect and sync with nearby devices</string>
<key>NSBonjourServices</key>
<array>
<string>_http-alt._tcp.</string>
</array>
3

Enable Bluetooth Background Modes:

XML
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
</array>

Initializing Ditto

Once you’ve installed the Ditto SDK, set the debug level you want Ditto to log messages for, create a new Ditto identity, and set up Ditto exception handling for data sync operations:

C#
try
{
    DittoLogger.SetMinimumLogLevel(DittoLogLevel.Debug);
    var ditto = new Ditto(DittoIdentity.OnlinePlayground("REPLACE_ME_WITH_YOUR_APP_ID", "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN", true), path);
    ditto.StartSync();
}
catch (DittoException ex)
{
    Console.WriteLine($"Ditto Error {ex.Message}");
}

Next Steps

Learn how to build a task list app built on .NET Maui and integrated with Ditto by going to the MAUI Task App how-to tutorial.

Was this page helpful?