Kill SDK¶
Completely Terminate the SDK¶
The kill() method completely terminates the SDK and clears all state. This is more destructive than endChat() which only disconnects the chat session.
What kill() does¶
When you call kill(), the SDK will:
- ๐ Disconnect the chat session (same as endChat())
- ๐งน Clear all session data including messages and context
- โก Reset SDK initialization state
- ๐ Clear bot key and authentication
- ๐จ Reset configuration and themes
- ๐ก Emit termination events for cleanup
After calling kill()¶
After calling kill(), the SDK returns to an uninitialized state:
- โ You cannot call displayChat() or other SDK methods
- โ
You must call start() again before using any SDK functions
- โ
All configuration (themes, permissions, etc.) needs to be set up again
Usage Examples¶
Complete SDK Shutdown¶
// Terminate the SDK completely
KindlySDK.kill().then { _ in
print("โ
SDK completely terminated")
// SDK is now in uninitialized state
}.catch { error in
print("โ Kill failed: \(error)")
}
Switch to Different Bot (Alternative Method)¶
// Method 1: Using kill() for explicit control
KindlySDK.kill().then { _ in
// SDK is now uninitialized - must call start() again
KindlySDK.start(botKey: "new-bot-key")
KindlySDK.displayChat()
}
// Method 2: Automatic switching (recommended)
KindlySDK.start(botKey: "new-bot-key") // SDK handles cleanup automatically
KindlySDK.displayChat()
When to Use kill() vs endChat()¶
Use kill() when:¶
- ๐ App shutdown: Terminating the app or major state changes
- ๐ Complete reset: Need to clear all SDK state and start fresh
- ๐ Error recovery: Recovering from SDK errors or corruption
- ๐งช Testing: Ensuring clean state between test runs
Use endChat() when:¶
- ๐ฌ End conversation: User finishes chatting but may return later
- ๐ Temporary disconnect: Preserving SDK state for quick reconnection
- ๐ฏ Normal flow: Standard chat lifecycle management
Comparison¶
| Method | Session | SDK State | Bot Key | Config | Next Action |
|---|---|---|---|---|---|
endChat() |
โ Cleared | โ Preserved | โ Preserved | โ Preserved | displayChat() |
kill() |
โ Cleared | โ Reset | โ Cleared | โ Reset | start() required |
Return Value¶
The kill() method returns a Promise<Void> that resolves when the termination is complete:
KindlySDK.kill()
.then { _ in
// SDK termination completed successfully
print("SDK killed successfully")
}
.catch { error in
// Handle any cleanup errors
print("Kill error: \(error)")
}
Best Practices¶
-
Always wait for completion before calling
start()again: -
Handle errors gracefully in case cleanup fails:
-
Use automatic bot switching instead of manual kill/start when possible:
For normal chat lifecycle management, prefer endChat() over kill().