Connect to an Atlas App Services backend - Swift SDK
On this page
Overview
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.
Access the App Client
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
Configuration
You can pass a configuration object to App
:
let configuration = AppConfiguration( baseURL: "https://realm.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
You Can't Change an App Config After Initializing the App
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.
Sync Connection Sharing
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)
Sync Timeout Options
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)
Supported Operating Systems
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.