Disconnect from Chat UI
Disconnect from the Chat SDK when your app needs to switch user accounts or log out. The SDK lets you control whether to allow push notifications after disconnection.
The SDK automatically reconnects when switching between foreground/background states or during network issues, ensuring reliable connections. Only call disconnect manually when implementing logout logic.
Disconnect (allow push notifications)
Actively disconnect from the Chat SDK while allowing the server to send push notifications. These two methods produce the same result:
Parameters
| Parameter | Type | Description |
|---|---|---|
| disablePush | BOOL | Whether to disable push notifications after disconnection. NO allows push notifications. YES disables them. |
Example code
- Swift
- Objective-C
NCChatUI.shared().disconnect()
[[NCChatUI shared] disconnect];
Or:
- Swift
- Objective-C
NCChatUI.shared().disconnect(disablePush: false)
[[NCChatUI shared] disconnectWithDisablePush:NO];
When the server detects an offline client, it stores offline messages and triggers push notifications. These typically appear as system notifications alerting the user about new messages.
Disconnect (block push notifications)
When logging out or switching user accounts, call this method to disconnect and prevent push notifications:
Parameters
| Parameter | Type | Description |
|---|---|---|
| disablePush | BOOL | Whether to disable push notifications after disconnection. YES blocks push notifications. |
Example code
- Swift
- Objective-C
NCChatUI.shared().disconnect(disablePush: true)
[[NCChatUI shared] disconnectWithDisablePush:YES];
When disconnecting with push notifications disabled, the server stores offline messages but won't trigger push notifications to the current device. If the user is logged in on multiple devices, only the most recently logged-in device receives pushes. For multi-device message consistency, enable multi-device sync. See multi-device message sync.