> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Enable Offline Support

> Turn on local caching and the durable send outbox, and verify offline support is active with the CometChat iOS SDK.

> [accordion] AI Integration Quick Reference
>
> ```swift theme={null}
> // 1. Build an OfflineConfig (off by default — call setEnabled(true)).
> let offlineConfig = OfflineConfig.Builder()
>     .setEnabled(true)
>     .build()
> // Swift shorthand: let offlineConfig = OfflineConfig(enabled: true)
>
> // 2. Attach it to AppSettings.
> let appSettings = AppSettings.AppSettingsBuilder()
>     .setRegion(region: "REGION")
>     .setOfflineConfig(offlineConfig)
>     .build()
>
> // 3. Pass the settings to init.
> CometChat.init(appId: "APP_ID", appSettings: appSettings, onSuccess: { _ in }, onError: { _ in })
>
> // 4. Verify it is active for the logged-in user.
> let active = CometChat.isOfflineEnabled()   // Bool
> ```

Offline support is **off by default**. You turn it on once, at initialization, by attaching an `OfflineConfig` to your `AppSettings`. Until you do, the SDK behaves exactly as before. This page covers the minimal setup; for every tunable option see the [Configuration & API Reference](https://www.cometchat.com/docs/sdk/ios/offline-reference.md).

**1. Requirements**

Offline support requires CometChat iOS SDK **4.2.0** or later. Update the dependency:

> [tab] CocoaPods
>
> ```ruby theme={null}
> pod 'CometChatSDK', '4.2.0'
> ```

> [tab] Swift Package Manager
>
> Set the `https://github.com/cometchat/chat-sdk-ios.git` dependency rule to `Up to Next Major Version` with version `4.2.0`.

If you are new to the SDK, complete the [standard setup](https://www.cometchat.com/docs/sdk/ios/setup.md) first; the steps below only add offline configuration to your existing `init`.

**2. Build an OfflineConfig**

Create an `OfflineConfig` and enable it. Every other field has a default, so set only what you need. In Swift you can use the initializer with default arguments. The `Builder` works from both Swift and Objective-C.

> [tab] Initializer
>
> ```swift theme={null}
> let offlineConfig = OfflineConfig(enabled: true)
> ```

> [tab] Builder
>
> ```swift theme={null}
> let offlineConfig = OfflineConfig.Builder()
>     .setEnabled(true)
>     .build()
> ```

**3. Attach it to AppSettings**

Pass the config to `AppSettingsBuilder.setOfflineConfig(_:)`. Without it, `AppSettings` keeps `OfflineConfig.default`, which has offline switched off.

```swift theme={null}
let appSettings = AppSettings.AppSettingsBuilder()
    .setRegion(region: "REGION")
    .setOfflineConfig(offlineConfig)
    .build()
```

**4. Initialize the SDK**

Pass the settings to `CometChat.init` as you do today. No other call changes.

```swift theme={null}
CometChat.init(appId: "APP_ID", appSettings: appSettings, onSuccess: { isSuccess in
    print("Initialization completed successfully")
}, onError: { error in
    print("Initialization failed: \(error.errorDescription)")
})
```

**5. Verify it is active**

Call `CometChat.isOfflineEnabled()`. It returns `true` only while offline support is actually active for the logged-in user. It is `false` before anyone logs in (even when you enabled it in `AppSettings`), after logout or session expiry, and when the encrypted cache cannot open. Read it at the moment of each decision and keep no copy of the result.

```swift theme={null}
let active = CometChat.isOfflineEnabled()
print("Offline support active: \(active)")
```

> [!NOTE]
>
> It is also `false` while the cache cannot run encrypted on this device and you chose `.onlineOnly` (see [Encrypt the Cache](https://www.cometchat.com/docs/sdk/ios/offline-encryption.md)). It is already `true` by the time any `onLoginSuccess` observer runs.

## Next steps

Offline support is now active for the logged-in user. Continue with [Show Cached Data](https://www.cometchat.com/docs/sdk/ios/offline-cached-data.md) to adopt the two-phase read overloads, and [Send While Offline](https://www.cometchat.com/docs/sdk/ios/offline-send.md) for the durable outbox. Tune caps, media, and encryption from the [Configuration & API Reference](https://www.cometchat.com/docs/sdk/ios/offline-reference.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.