Installing Swift SDK
You can integrate the Ditto SDK into Swift projects to develop native apps for Apple iOS and macOS platforms.
For a complete overview of the platforms, transports, and devices the Swift SDK supports, see Compatibility with Swift.
To install the Ditto SDK and start syncing offline:
Confirm that you meet the minimum requirements. (Prerequisites)
Install the necessary dependencies. (Adding 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
- macOS version 11
From your project in Xcode:
Click File and then select Add Packages... from the menu.
In the Recently Used dialog box, copy-paste the following URL into the search box located in the upper right corner.
For more information, see the official Apple documentation > Adding package dependencies to your app.
Click to select DittoObjC and DittoSwift > and then click Add Package.
Once you've added dependencies:
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 the Installing Swift SDK > Configuring Permissions topic.
From your project's Info.plistfile, add the following key-value pairs, and then, if applicable, modify each string assigned to Value:
- Once implemented, the following string values display as a prompt to your end users explaining why the app requires certain permissions.
- If your end users prefer a language other than English, replace the string values with their language equivalents.
Setting the Data Protection entitlement to NSFileProtectionComplete may lead to a crash.
To mitigate the crash, set the Data Protection entitlement to NSFileProtectionCompleteUntilFirstUserAuthentication.
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
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, see Ditto Basics > Authentication and Initialization.
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 Onboarding. For an introduction to authentication in Ditto, see Ditto Basics > Authentication and Initialization.