Swift
You can integrate the Ditto SDK into Swift projects to develop native apps for Apple iOS and macOS platforms.
To install the Ditto SDK and start syncing offline:
Confirm that you meet the minimum requirements. (Prerequisites)
Install the necessary dependencies. (Installing Package Dependencies)
Set up your app permissions. (Configuring Permissions)
Authenticate with the Big Peer and then start syncing offline. (Integrating and Initializing Sync)
Following are the minimum requirements that must be met before attempting to install Ditto:
- iOS version 14 or later
- Mac Catalyst 14 or later
- macOS (AppKit) version 11 or later
- tvOS version 14 or later
- (optional) visionOS version 1, 1.1, or 1.2
Using Xcode or CocoaPods, add the necessary dependencies:
Click File, and then select Add Package Dependencies... from the menu.
In the modal that appears:
- Copy-paste the following URL into the search box in the upper-right corner: https://github.com/getditto/DittoSwiftPackage
- Select dittoswiftpackage from the list.
- Click Dependency Rule and select the version of Ditto you want to use:
- Click Add Package.
For more information, see the official Apple documentation > Adding package dependencies to your app.
From the Choose Package Products for DittoSwiftPackage modal:
- Click Add to Target and select your app from the list.
- Click Add Package.
Developing for Production
To install the latest production release of the Ditto SDK for Swift:
Click the Dependency Rule dropdown menu and select Up to Next Major Version from the list.
In the field on the right, set the version to 4.7.2.
Exploring with visionOS beta
Ditto now supports the visionOS platform in beta for our Swift SDK.
For an overview of the Ditto SDK for visionOS, including steps outlining example integration with our demo chat app, DittoChat, see visionOS on Swift.
To install the visionOS beta Ditto Swift package, set the Dependency Rule to 4.8.0-v as follows:
Click the Dependency Rule dropdown menu and select Exact Version from the list.
In the field on the right, set the version to 4.7.2.
For the visionOS binaries in GitHub, see 4.8.0-visionos-beta.1 library in the DittoSwiftPackage repo.
Once you've added Ditto SDK package dependencies:
Configure your project's Info.plist file to ensure the necessary permissions for Bluetooth Low Energy (LE) and local network services are included. (Ensuring Privacy Compliance)
If enabling the Data Protection entitlement, allow access after your end users have unlocked their device for the first time after a system restart. (Setting Protection Entitlement)
Configure your app for compliance with Apple's guidelines for iOS permissions by doing the following. For more information, see the official Apple documentation for Privacy.
From Xcode, add a new Custom iOS Target Properties entry:
- From the left navigator area, click your project.
- In the editor that appears, click Info tab.
- Right-click any row in the list, and then select Add Row from the menu.
For instructions on configuring permissions for your app, see Cloud Authentication.
From your project's Info.plistfile, add the following key-value pairs, which display as dismissable prompts to your end users explaining why the app requires certain permissions.
If your end users prefer a language other than English, replace each default string assigned to Value with their language equivalents.
From Xcode, ensure your app continues to sync while it runs in the background, as well as when the end-user device is locked by enabling Bluetooth Background Modes:
- From the left navigator area, click your project.
- Click Signing & Capabilities.
- Click + Capability and then, from the modal that appears, search and select Background Modes.
- From TARGETS, select your app from the list.
- From Background Modes, click to select the following:
- Uses Bluetooth LE accessories
- Acts as a Bluetooth LE accessory
If enabling the Data Protection entitlement, allow access after the end user has unlocked their device for the first time after a system restart by setting the entitlement to NSFileProtectionCompleteUntilFirstUserAuthentication.
For more information, see the official Apple documentation for Data Protection Entitlement.
Once you've set up your environment, import the Ditto SDK in your codebase and obtain your access credentials.
Unless you have a specialized use case, such as a government app, you must connect to the internet at least once before you can sync offline with other peers.
For more information, contact Ditto. (See Contact Us)
From the top-most scope of your app's codebase, add the following to set up authentication and start syncing offline.
Replace YOUR_APP_ID and YOUR_PLAYGROUND_TOKEN with your access credentials available from the portal.
For instructions on how to obtain your access credentials, see Getting Playground Token Credentials