Docs Menu

Docs HomeDevelop ApplicationsAtlas Device SDK

Connect to an Atlas App Services Backend - Swift SDK

On this page

  • Access the App Client
  • Configuration
  • Sync Connection Sharing
  • Sync Timeout Options
  • Supported Operating Systems

The App client is the interface to the App Services backend. It provides access to the authentication functionality, functions, querying a MongoDB Atlas data source, and Device Sync.

Note

Apple Privacy Manifest

The SDK's Apple privacy manifest does not cover connecting to Atlas, or any usage of data through the App client. If your app connects to App Services, and you intend to distribute it through the Apple App Store, you may need to provide your own disclosures in your app's Apple privacy manifest.

For more information, refer to Apple Privacy Manifest.

Pass the App ID for your App, which you can find in the App Services UI.

let app = App(id: YOUR_APP_SERVICES_APP_ID) // replace YOUR_APP_SERVICES_APP_ID with your App ID

You can pass a configuration object to App:

let configuration = AppConfiguration(
baseURL: "https://services.cloud.mongodb.com", // Custom base URL
transport: nil, // Custom RLMNetworkTransportProtocol
localAppName: "My App",
localAppVersion: "3.14.159",
defaultRequestTimeoutMS: 30000
)
let app = App(id: "my-app-services-app-id", configuration: configuration)

You can create multiple App client instances to connect to multiple Apps. All App client instances that share the same App ID use the same underlying connection.

Important

Changing an App Config After Initializing the App

Starting with Swift SDK version 10.46.0, you can change a baseURL in the App config and the App client uses the new baseURL. In Swift SDK versions 10.45.3 and earlier, when you initialize the App client, the configuration is cached internally. Attempting to "close" an App and then re-open it with a changed configuration within the same process has no effect. The client continues to use the cached configuration.

New in version 10.41.0.

You can set the enableSessionMultiplexing bool on the AppConfiguration to specify whether the Realm Swift SDK should open a connection to the server for each synced realm, or share a connection to the server for all synced realms.

If you do not specify a value for this bool, Realm defaults to sharing a single connection per App Services user for all synced realms.

let configuration = AppConfiguration(enableSessionMultiplexing: false)
let app = App(id: YOUR_APP_SERVICES_APP_ID, configuration: configuration)

New in version 10.41.0.

You can set various sync timeout options on the AppConfiguration. The syncTimeouts property can accept a SyncTimeoutOptions object to override default values for these settings.

For a complete list of the available timeout settings and their definitions, refer to RLMSyncTimeoutOptions.

let syncTimeoutOptions = SyncTimeoutOptions(
connectTimeout: 30000,
connectionLingerTime: 5000,
pingKeepalivePeriod: 10000,
pongKeepaliveTimeout: 10000,
fastReconnectLimit: 30000
)
let configuration = AppConfiguration(syncTimeouts: syncTimeoutOptions)
let app = App(id: YOUR_APP_SERVICES_APP_ID, configuration: configuration)

The Realm Swift SDK supports connecting to an Atlas App Services App for a range of Apple operating systems depending on the Xcode version and Realm Swift SDK version. Connecting to an App Services App enables:

  • Authentication and User Management

  • Calling an Atlas Function

  • Querying a MongoDB Atlas Data Source

  • Device Sync

For current information about supported operating systems, refer to OS Support.

At this time, the Realm Swift SDK does not support connecting to an App Services App from watchOS.

←  Application Services - Swift SDKCall a Function - Swift SDK →