@cometchat/skills 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -17
  3. package/bin/install.js +389 -43
  4. package/package.json +19 -9
  5. package/skills/cometchat/SKILL.md +1066 -265
  6. package/skills/cometchat-android-v5/SKILL.md +120 -0
  7. package/skills/cometchat-android-v5-components/SKILL.md +430 -0
  8. package/skills/cometchat-android-v5-core/SKILL.md +468 -0
  9. package/skills/cometchat-android-v5-customization/SKILL.md +305 -0
  10. package/skills/cometchat-android-v5-extensions/SKILL.md +124 -0
  11. package/skills/cometchat-android-v5-features/SKILL.md +130 -0
  12. package/skills/cometchat-android-v5-placement/SKILL.md +276 -0
  13. package/skills/cometchat-android-v5-production/SKILL.md +94 -0
  14. package/skills/cometchat-android-v5-push/SKILL.md +620 -0
  15. package/skills/cometchat-android-v5-testing/SKILL.md +187 -0
  16. package/skills/cometchat-android-v5-theming/SKILL.md +166 -0
  17. package/skills/cometchat-android-v5-troubleshooting/SKILL.md +73 -0
  18. package/skills/cometchat-android-v6/SKILL.md +107 -0
  19. package/skills/cometchat-android-v6-builder-settings/SKILL.md +145 -0
  20. package/skills/cometchat-android-v6-compose-components/SKILL.md +202 -0
  21. package/skills/cometchat-android-v6-compose-customization/SKILL.md +280 -0
  22. package/skills/cometchat-android-v6-compose-placement/SKILL.md +213 -0
  23. package/skills/cometchat-android-v6-compose-theming/SKILL.md +224 -0
  24. package/skills/cometchat-android-v6-core/SKILL.md +354 -0
  25. package/skills/cometchat-android-v6-events/SKILL.md +212 -0
  26. package/skills/cometchat-android-v6-extensions/SKILL.md +191 -0
  27. package/skills/cometchat-android-v6-features/SKILL.md +130 -0
  28. package/skills/cometchat-android-v6-kotlin-components/SKILL.md +197 -0
  29. package/skills/cometchat-android-v6-kotlin-customization/SKILL.md +268 -0
  30. package/skills/cometchat-android-v6-kotlin-placement/SKILL.md +248 -0
  31. package/skills/cometchat-android-v6-kotlin-theming/SKILL.md +202 -0
  32. package/skills/cometchat-android-v6-production/SKILL.md +187 -0
  33. package/skills/cometchat-android-v6-push/SKILL.md +274 -0
  34. package/skills/cometchat-android-v6-testing/SKILL.md +279 -0
  35. package/skills/cometchat-android-v6-troubleshooting/SKILL.md +249 -0
  36. package/skills/cometchat-angular-components/SKILL.md +706 -0
  37. package/skills/cometchat-angular-core/SKILL.md +444 -0
  38. package/skills/cometchat-angular-customization/SKILL.md +424 -0
  39. package/skills/cometchat-angular-features/SKILL.md +447 -0
  40. package/skills/cometchat-angular-patterns/SKILL.md +447 -0
  41. package/skills/cometchat-angular-placement/SKILL.md +685 -0
  42. package/skills/cometchat-angular-production/SKILL.md +415 -0
  43. package/skills/cometchat-angular-theming/SKILL.md +365 -0
  44. package/skills/cometchat-angular-troubleshooting/SKILL.md +329 -0
  45. package/skills/cometchat-astro-patterns/SKILL.md +3 -3
  46. package/skills/cometchat-components/SKILL.md +11 -0
  47. package/skills/cometchat-core/SKILL.md +11 -6
  48. package/skills/cometchat-customization/references/component-catalog.md +1 -1
  49. package/skills/cometchat-features/SKILL.md +176 -108
  50. package/skills/cometchat-flutter-v5/SKILL.md +167 -0
  51. package/skills/cometchat-flutter-v5-calls/SKILL.md +192 -0
  52. package/skills/cometchat-flutter-v5-conversations/SKILL.md +117 -0
  53. package/skills/cometchat-flutter-v5-core/SKILL.md +221 -0
  54. package/skills/cometchat-flutter-v5-customization/SKILL.md +227 -0
  55. package/skills/cometchat-flutter-v5-events/SKILL.md +155 -0
  56. package/skills/cometchat-flutter-v5-messages/SKILL.md +258 -0
  57. package/skills/cometchat-flutter-v5-production/SKILL.md +207 -0
  58. package/skills/cometchat-flutter-v5-push/SKILL.md +284 -0
  59. package/skills/cometchat-flutter-v5-theming/SKILL.md +160 -0
  60. package/skills/cometchat-flutter-v5-troubleshooting/SKILL.md +129 -0
  61. package/skills/cometchat-flutter-v5-users-groups/SKILL.md +151 -0
  62. package/skills/cometchat-flutter-v6/SKILL.md +445 -0
  63. package/skills/cometchat-flutter-v6-calls/SKILL.md +333 -0
  64. package/skills/cometchat-flutter-v6-components/SKILL.md +365 -0
  65. package/skills/cometchat-flutter-v6-conversations/SKILL.md +210 -0
  66. package/skills/cometchat-flutter-v6-core/SKILL.md +305 -0
  67. package/skills/cometchat-flutter-v6-customization/SKILL.md +666 -0
  68. package/skills/cometchat-flutter-v6-events/SKILL.md +216 -0
  69. package/skills/cometchat-flutter-v6-features/SKILL.md +406 -0
  70. package/skills/cometchat-flutter-v6-messages/SKILL.md +333 -0
  71. package/skills/cometchat-flutter-v6-migration/SKILL.md +381 -0
  72. package/skills/cometchat-flutter-v6-placement/SKILL.md +398 -0
  73. package/skills/cometchat-flutter-v6-production/SKILL.md +632 -0
  74. package/skills/cometchat-flutter-v6-theming/SKILL.md +260 -0
  75. package/skills/cometchat-flutter-v6-troubleshooting/SKILL.md +726 -0
  76. package/skills/cometchat-flutter-v6-users-groups/SKILL.md +216 -0
  77. package/skills/cometchat-ios/SKILL.md +323 -0
  78. package/skills/cometchat-ios-components/SKILL.md +651 -0
  79. package/skills/cometchat-ios-core/SKILL.md +822 -0
  80. package/skills/cometchat-ios-customization/SKILL.md +825 -0
  81. package/skills/cometchat-ios-features/SKILL.md +725 -0
  82. package/skills/cometchat-ios-placement/SKILL.md +750 -0
  83. package/skills/cometchat-ios-production/SKILL.md +730 -0
  84. package/skills/cometchat-ios-push/SKILL.md +582 -0
  85. package/skills/cometchat-ios-theming/SKILL.md +631 -0
  86. package/skills/cometchat-ios-troubleshooting/SKILL.md +983 -0
  87. package/skills/cometchat-native-bare-patterns/SKILL.md +470 -0
  88. package/skills/cometchat-native-components/SKILL.md +594 -0
  89. package/skills/cometchat-native-core/SKILL.md +407 -0
  90. package/skills/cometchat-native-customization/SKILL.md +594 -0
  91. package/skills/cometchat-native-expo-patterns/SKILL.md +485 -0
  92. package/skills/cometchat-native-features/SKILL.md +608 -0
  93. package/skills/cometchat-native-placement/SKILL.md +500 -0
  94. package/skills/cometchat-native-production/SKILL.md +694 -0
  95. package/skills/cometchat-native-push/SKILL.md +593 -0
  96. package/skills/cometchat-native-testing/SKILL.md +583 -0
  97. package/skills/cometchat-native-theming/SKILL.md +656 -0
  98. package/skills/cometchat-native-troubleshooting/SKILL.md +433 -0
  99. package/skills/cometchat-nextjs-patterns/SKILL.md +5 -5
  100. package/skills/cometchat-production/SKILL.md +60 -0
  101. package/skills/cometchat-react-router-patterns/SKILL.md +23 -21
@@ -0,0 +1,730 @@
1
+ ---
2
+ name: cometchat-ios-production
3
+ description: "Production-ready CometChat iOS setup — server-side auth tokens, security best practices, and deployment checklist."
4
+ license: "MIT"
5
+ compatibility: "CometChatUIKitSwift ^5; iOS 13+"
6
+ allowed-tools: "executeBash, readFile, fileSearch, listDirectory"
7
+ metadata:
8
+ author: "CometChat"
9
+ version: "3.0.0"
10
+ tags: "chat cometchat ios production auth tokens security deployment"
11
+ ---
12
+
13
+ ## Purpose
14
+
15
+ This skill teaches how to prepare your CometChat iOS integration for production. It covers replacing development Auth Keys with server-side auth tokens, security best practices, and a deployment checklist.
16
+
17
+ ---
18
+
19
+ ## 1. Development vs Production Authentication
20
+
21
+ ### Development Mode (Auth Key)
22
+
23
+ In development, you use the Auth Key directly in your app:
24
+
25
+ ```swift
26
+ // ⚠️ DEVELOPMENT ONLY — Never ship this to production
27
+ CometChatUIKit.login(uid: "user-123") { result in
28
+ // ...
29
+ }
30
+ ```
31
+
32
+ **Problems with Auth Key in production:**
33
+ - Auth Key is embedded in your app binary
34
+ - Anyone can decompile your app and extract it
35
+ - Attackers can impersonate any user
36
+ - No server-side validation of user identity
37
+
38
+ ### Production Mode (Auth Token)
39
+
40
+ In production, your server generates short-lived auth tokens:
41
+
42
+ ```
43
+ ┌─────────────┐ 1. Login ┌─────────────┐
44
+ │ iOS App │ ───────────────► │ Your Server │
45
+ └─────────────┘ └─────────────┘
46
+ │ │
47
+ │ │ 2. Verify user
48
+ │ │ Generate token
49
+ │ ▼
50
+ │ ┌─────────────┐
51
+ │ │ CometChat │
52
+ │ │ API │
53
+ │ └─────────────┘
54
+ │ │
55
+ │ 3. Return auth token │
56
+ │ ◄──────────────────────────────┘
57
+
58
+ │ 4. Login with token
59
+
60
+ ┌─────────────┐
61
+ │ CometChat │
62
+ │ SDK │
63
+ └─────────────┘
64
+ ```
65
+
66
+ ---
67
+
68
+ ## 2. Server-Side Token Generation
69
+
70
+ ### Your Server Endpoint
71
+
72
+ Create an endpoint that:
73
+ 1. Authenticates the user (your existing auth system)
74
+ 2. Calls CometChat API to generate an auth token
75
+ 3. Returns the token to the iOS app
76
+
77
+ **Example (Node.js/Express):**
78
+
79
+ ```javascript
80
+ const express = require('express');
81
+ const axios = require('axios');
82
+
83
+ const app = express();
84
+
85
+ const COMETCHAT_APP_ID = process.env.COMETCHAT_APP_ID;
86
+ const COMETCHAT_API_KEY = process.env.COMETCHAT_API_KEY; // REST API Key
87
+ const COMETCHAT_REGION = process.env.COMETCHAT_REGION;
88
+
89
+ app.post('/api/cometchat/token', async (req, res) => {
90
+ try {
91
+ // 1. Verify the user is authenticated (your auth system)
92
+ const userId = req.user.id; // From your auth middleware
93
+
94
+ if (!userId) {
95
+ return res.status(401).json({ error: 'Unauthorized' });
96
+ }
97
+
98
+ // 2. Generate CometChat auth token
99
+ const response = await axios.post(
100
+ `https://${COMETCHAT_APP_ID}.api-${COMETCHAT_REGION}.cometchat.io/v3/users/${userId}/auth_tokens`,
101
+ {},
102
+ {
103
+ headers: {
104
+ 'apiKey': COMETCHAT_API_KEY,
105
+ 'Content-Type': 'application/json'
106
+ }
107
+ }
108
+ );
109
+
110
+ // 3. Return the token
111
+ res.json({
112
+ authToken: response.data.data.authToken
113
+ });
114
+
115
+ } catch (error) {
116
+ console.error('CometChat token error:', error.response?.data || error.message);
117
+ res.status(500).json({ error: 'Failed to generate token' });
118
+ }
119
+ });
120
+ ```
121
+
122
+ **Example (Python/Flask):**
123
+
124
+ ```python
125
+ from flask import Flask, jsonify, request
126
+ import requests
127
+ import os
128
+
129
+ app = Flask(__name__)
130
+
131
+ COMETCHAT_APP_ID = os.environ.get('COMETCHAT_APP_ID')
132
+ COMETCHAT_API_KEY = os.environ.get('COMETCHAT_API_KEY')
133
+ COMETCHAT_REGION = os.environ.get('COMETCHAT_REGION')
134
+
135
+ @app.route('/api/cometchat/token', methods=['POST'])
136
+ def get_cometchat_token():
137
+ # 1. Verify user is authenticated (your auth system)
138
+ user_id = request.user.id # From your auth middleware
139
+
140
+ if not user_id:
141
+ return jsonify({'error': 'Unauthorized'}), 401
142
+
143
+ # 2. Generate CometChat auth token
144
+ url = f'https://{COMETCHAT_APP_ID}.api-{COMETCHAT_REGION}.cometchat.io/v3/users/{user_id}/auth_tokens'
145
+
146
+ headers = {
147
+ 'apiKey': COMETCHAT_API_KEY,
148
+ 'Content-Type': 'application/json'
149
+ }
150
+
151
+ response = requests.post(url, headers=headers)
152
+
153
+ if response.status_code == 200:
154
+ data = response.json()
155
+ return jsonify({'authToken': data['data']['authToken']})
156
+ else:
157
+ return jsonify({'error': 'Failed to generate token'}), 500
158
+ ```
159
+
160
+ ### CometChat REST API Reference
161
+
162
+ **Create Auth Token:**
163
+ ```
164
+ POST https://{appId}.api-{region}.cometchat.io/v3/users/{uid}/auth_tokens
165
+
166
+ Headers:
167
+ apiKey: YOUR_REST_API_KEY
168
+ Content-Type: application/json
169
+
170
+ Response:
171
+ {
172
+ "data": {
173
+ "uid": "user-123",
174
+ "authToken": "user-123_abc123xyz..."
175
+ }
176
+ }
177
+ ```
178
+
179
+ **Create User (if needed):**
180
+ ```
181
+ POST https://{appId}.api-{region}.cometchat.io/v3/users
182
+
183
+ Headers:
184
+ apiKey: YOUR_REST_API_KEY
185
+ Content-Type: application/json
186
+
187
+ Body:
188
+ {
189
+ "uid": "user-123",
190
+ "name": "John Doe",
191
+ "avatar": "https://example.com/avatar.jpg"
192
+ }
193
+ ```
194
+
195
+ ---
196
+
197
+ ## 3. iOS Implementation
198
+
199
+ ### CometChatManager for Production
200
+
201
+ ```swift
202
+ import Foundation
203
+ import CometChatUIKitSwift
204
+ import CometChatSDK
205
+
206
+ final class CometChatManager {
207
+
208
+ static let shared = CometChatManager()
209
+
210
+ private(set) var isInitialized = false
211
+ private(set) var currentUser: User?
212
+
213
+ private init() {}
214
+
215
+ // MARK: - Initialization (No Auth Key needed)
216
+
217
+ func initialize(completion: @escaping (Result<Bool, Error>) -> Void) {
218
+ guard !isInitialized else {
219
+ completion(.success(true))
220
+ return
221
+ }
222
+
223
+ // Note: No authKey in production!
224
+ let uiKitSettings = UIKitSettings()
225
+ .set(appID: AppConfig.cometChatAppID)
226
+ .set(region: AppConfig.cometChatRegion)
227
+ .subscribePresenceForAllUsers()
228
+ .build()
229
+
230
+ CometChatUIKit(uiKitSettings: uiKitSettings) { [weak self] result in
231
+ DispatchQueue.main.async {
232
+ switch result {
233
+ case .success(let success):
234
+ self?.isInitialized = success
235
+ self?.currentUser = CometChatUIKit.getLoggedInUser()
236
+ completion(.success(success))
237
+ case .failure(let error):
238
+ completion(.failure(error))
239
+ }
240
+ }
241
+ }
242
+ }
243
+
244
+ // MARK: - Production Login
245
+
246
+ func login(completion: @escaping (Result<User, Error>) -> Void) {
247
+ guard isInitialized else {
248
+ completion(.failure(CometChatError.notInitialized))
249
+ return
250
+ }
251
+
252
+ // Check for existing session
253
+ if let user = CometChatUIKit.getLoggedInUser() {
254
+ currentUser = user
255
+ completion(.success(user))
256
+ return
257
+ }
258
+
259
+ // Fetch auth token from your server
260
+ fetchAuthToken { [weak self] result in
261
+ switch result {
262
+ case .success(let authToken):
263
+ self?.loginWithToken(authToken, completion: completion)
264
+ case .failure(let error):
265
+ completion(.failure(error))
266
+ }
267
+ }
268
+ }
269
+
270
+ private func fetchAuthToken(completion: @escaping (Result<String, Error>) -> Void) {
271
+ guard let url = URL(string: "\(AppConfig.apiBaseURL)/api/cometchat/token") else {
272
+ completion(.failure(CometChatError.invalidURL))
273
+ return
274
+ }
275
+
276
+ var request = URLRequest(url: url)
277
+ request.httpMethod = "POST"
278
+ request.setValue("application/json", forHTTPHeaderField: "Content-Type")
279
+
280
+ // Add your auth header (e.g., JWT token)
281
+ if let authToken = AuthManager.shared.accessToken {
282
+ request.setValue("Bearer \(authToken)", forHTTPHeaderField: "Authorization")
283
+ }
284
+
285
+ URLSession.shared.dataTask(with: request) { data, response, error in
286
+ if let error = error {
287
+ completion(.failure(error))
288
+ return
289
+ }
290
+
291
+ guard let data = data else {
292
+ completion(.failure(CometChatError.noData))
293
+ return
294
+ }
295
+
296
+ do {
297
+ let json = try JSONSerialization.jsonObject(with: data) as? [String: Any]
298
+ if let authToken = json?["authToken"] as? String {
299
+ completion(.success(authToken))
300
+ } else {
301
+ completion(.failure(CometChatError.invalidResponse))
302
+ }
303
+ } catch {
304
+ completion(.failure(error))
305
+ }
306
+ }.resume()
307
+ }
308
+
309
+ private func loginWithToken(_ authToken: String, completion: @escaping (Result<User, Error>) -> Void) {
310
+ CometChatUIKit.login(authToken: authToken) { [weak self] result in
311
+ DispatchQueue.main.async {
312
+ switch result {
313
+ case .success(let user):
314
+ self?.currentUser = user
315
+ completion(.success(user))
316
+ case .onError(let error):
317
+ completion(.failure(error))
318
+ }
319
+ }
320
+ }
321
+ }
322
+
323
+ // MARK: - Logout
324
+
325
+ func logout(completion: @escaping (Result<Void, Error>) -> Void) {
326
+ guard let user = currentUser else {
327
+ completion(.success(()))
328
+ return
329
+ }
330
+
331
+ CometChatUIKit.logout(user: user) { [weak self] result in
332
+ DispatchQueue.main.async {
333
+ switch result {
334
+ case .success:
335
+ self?.currentUser = nil
336
+ completion(.success(()))
337
+ case .onError(let error):
338
+ completion(.failure(error))
339
+ }
340
+ }
341
+ }
342
+ }
343
+ }
344
+
345
+ // MARK: - Errors
346
+
347
+ enum CometChatError: LocalizedError {
348
+ case notInitialized
349
+ case invalidURL
350
+ case noData
351
+ case invalidResponse
352
+
353
+ var errorDescription: String? {
354
+ switch self {
355
+ case .notInitialized:
356
+ return "CometChat is not initialized"
357
+ case .invalidURL:
358
+ return "Invalid API URL"
359
+ case .noData:
360
+ return "No data received from server"
361
+ case .invalidResponse:
362
+ return "Invalid response from server"
363
+ }
364
+ }
365
+ }
366
+ ```
367
+
368
+ ### App Configuration
369
+
370
+ ```swift
371
+ // AppConfig.swift
372
+ import Foundation
373
+
374
+ struct AppConfig {
375
+
376
+ // CometChat
377
+ static let cometChatAppID: String = {
378
+ guard let appID = Bundle.main.object(forInfoDictionaryKey: "CometChatAppID") as? String else {
379
+ fatalError("CometChatAppID not found in Info.plist")
380
+ }
381
+ return appID
382
+ }()
383
+
384
+ static let cometChatRegion: String = {
385
+ guard let region = Bundle.main.object(forInfoDictionaryKey: "CometChatRegion") as? String else {
386
+ fatalError("CometChatRegion not found in Info.plist")
387
+ }
388
+ return region
389
+ }()
390
+
391
+ // Your API
392
+ static let apiBaseURL: String = {
393
+ #if DEBUG
394
+ return "https://api-staging.yourapp.com"
395
+ #else
396
+ return "https://api.yourapp.com"
397
+ #endif
398
+ }()
399
+ }
400
+ ```
401
+
402
+ ### Info.plist Configuration
403
+
404
+ ```xml
405
+ <key>CometChatAppID</key>
406
+ <string>$(COMETCHAT_APP_ID)</string>
407
+ <key>CometChatRegion</key>
408
+ <string>$(COMETCHAT_REGION)</string>
409
+ ```
410
+
411
+ ### xcconfig Files
412
+
413
+ **Debug.xcconfig:**
414
+ ```
415
+ COMETCHAT_APP_ID = your_app_id
416
+ COMETCHAT_REGION = us
417
+ ```
418
+
419
+ **Release.xcconfig:**
420
+ ```
421
+ COMETCHAT_APP_ID = your_app_id
422
+ COMETCHAT_REGION = us
423
+ ```
424
+
425
+ ---
426
+
427
+ ## 4. User Provisioning
428
+
429
+ ### Create Users on Your Server
430
+
431
+ When a user signs up in your app, create them in CometChat:
432
+
433
+ ```javascript
434
+ // On your server - user registration endpoint
435
+ app.post('/api/register', async (req, res) => {
436
+ const { email, password, name } = req.body;
437
+
438
+ // 1. Create user in your database
439
+ const user = await createUserInDatabase({ email, password, name });
440
+
441
+ // 2. Create user in CometChat
442
+ await axios.post(
443
+ `https://${COMETCHAT_APP_ID}.api-${COMETCHAT_REGION}.cometchat.io/v3/users`,
444
+ {
445
+ uid: user.id,
446
+ name: user.name,
447
+ avatar: user.avatarUrl
448
+ },
449
+ {
450
+ headers: {
451
+ 'apiKey': COMETCHAT_API_KEY,
452
+ 'Content-Type': 'application/json'
453
+ }
454
+ }
455
+ );
456
+
457
+ res.json({ success: true, userId: user.id });
458
+ });
459
+ ```
460
+
461
+ ### Update User Profile
462
+
463
+ When user updates their profile:
464
+
465
+ ```javascript
466
+ app.put('/api/profile', async (req, res) => {
467
+ const { name, avatar } = req.body;
468
+ const userId = req.user.id;
469
+
470
+ // 1. Update in your database
471
+ await updateUserInDatabase(userId, { name, avatar });
472
+
473
+ // 2. Update in CometChat
474
+ await axios.put(
475
+ `https://${COMETCHAT_APP_ID}.api-${COMETCHAT_REGION}.cometchat.io/v3/users/${userId}`,
476
+ { name, avatar },
477
+ {
478
+ headers: {
479
+ 'apiKey': COMETCHAT_API_KEY,
480
+ 'Content-Type': 'application/json'
481
+ }
482
+ }
483
+ );
484
+
485
+ res.json({ success: true });
486
+ });
487
+ ```
488
+
489
+ ---
490
+
491
+ ## 5. Security Best Practices
492
+
493
+ ### Never Expose API Keys
494
+
495
+ ❌ **Wrong:**
496
+ ```swift
497
+ // Never do this!
498
+ let apiKey = "abc123xyz" // Hardcoded in app
499
+ ```
500
+
501
+ ✅ **Correct:**
502
+ ```swift
503
+ // API keys stay on your server
504
+ // iOS app only receives short-lived auth tokens
505
+ ```
506
+
507
+ ### Validate User Identity
508
+
509
+ Always verify user identity on your server before generating tokens:
510
+
511
+ ```javascript
512
+ app.post('/api/cometchat/token', authenticateMiddleware, async (req, res) => {
513
+ // authenticateMiddleware verifies the user's JWT/session
514
+ const userId = req.user.id; // Verified user ID
515
+
516
+ // Generate token only for verified users
517
+ // ...
518
+ });
519
+ ```
520
+
521
+ ### Use HTTPS
522
+
523
+ Always use HTTPS for API communication:
524
+
525
+ ```swift
526
+ // ✅ Correct
527
+ let url = URL(string: "https://api.yourapp.com/api/cometchat/token")
528
+
529
+ // ❌ Wrong
530
+ let url = URL(string: "http://api.yourapp.com/api/cometchat/token")
531
+ ```
532
+
533
+ ### Token Expiration
534
+
535
+ Auth tokens have a default expiration. Handle token refresh:
536
+
537
+ ```swift
538
+ func handleTokenExpired() {
539
+ // Clear current session
540
+ CometChatManager.shared.logout { _ in
541
+ // Re-login to get new token
542
+ CometChatManager.shared.login { result in
543
+ switch result {
544
+ case .success:
545
+ print("Re-authenticated successfully")
546
+ case .failure(let error):
547
+ print("Re-authentication failed: \(error)")
548
+ // Navigate to login screen
549
+ }
550
+ }
551
+ }
552
+ }
553
+ ```
554
+
555
+ ### App Transport Security
556
+
557
+ Ensure ATS is properly configured in `Info.plist`:
558
+
559
+ ```xml
560
+ <key>NSAppTransportSecurity</key>
561
+ <dict>
562
+ <key>NSAllowsArbitraryLoads</key>
563
+ <false/>
564
+ </dict>
565
+ ```
566
+
567
+ ---
568
+
569
+ ## 6. Error Handling
570
+
571
+ ### Handle Authentication Errors
572
+
573
+ ```swift
574
+ func handleCometChatError(_ error: Error) {
575
+ if let cometChatError = error as? CometChatException {
576
+ switch cometChatError.errorCode {
577
+ case "ERR_UID_NOT_FOUND":
578
+ // User doesn't exist in CometChat
579
+ // Create user on your server, then retry
580
+ createUserAndRetry()
581
+
582
+ case "AUTH_ERR_AUTH_TOKEN_NOT_FOUND":
583
+ // Invalid or expired token
584
+ refreshTokenAndRetry()
585
+
586
+ case "ERR_NOT_LOGGED_IN":
587
+ // User not logged in
588
+ navigateToLogin()
589
+
590
+ default:
591
+ showError(cometChatError.errorDescription ?? "Unknown error")
592
+ }
593
+ }
594
+ }
595
+ ```
596
+
597
+ ### Retry Logic
598
+
599
+ ```swift
600
+ func loginWithRetry(maxAttempts: Int = 3, completion: @escaping (Result<User, Error>) -> Void) {
601
+ var attempts = 0
602
+
603
+ func attempt() {
604
+ attempts += 1
605
+
606
+ CometChatManager.shared.login { result in
607
+ switch result {
608
+ case .success(let user):
609
+ completion(.success(user))
610
+ case .failure(let error):
611
+ if attempts < maxAttempts {
612
+ // Wait and retry
613
+ DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
614
+ attempt()
615
+ }
616
+ } else {
617
+ completion(.failure(error))
618
+ }
619
+ }
620
+ }
621
+ }
622
+
623
+ attempt()
624
+ }
625
+ ```
626
+
627
+ ---
628
+
629
+ ## 7. Deployment Checklist
630
+
631
+ ### Before Submitting to App Store
632
+
633
+ - [ ] **Remove Auth Key from code** — Use server-side tokens only
634
+ - [ ] **Configure production API URL** — Point to production server
635
+ - [ ] **Test with production CometChat app** — Create separate prod app in dashboard
636
+ - [ ] **Enable required extensions** — Polls, stickers, AI features in dashboard
637
+ - [ ] **Configure push notifications** — Upload APNs certificate to dashboard
638
+ - [ ] **Test on real devices** — Calls and push don't work on simulator
639
+ - [ ] **Review Info.plist permissions** — Camera, microphone, notifications
640
+ - [ ] **Test logout flow** — Ensure clean session termination
641
+ - [ ] **Test offline behavior** — App should handle network issues gracefully
642
+ - [ ] **Review error messages** — User-friendly error handling
643
+
644
+ ### CometChat Dashboard Configuration
645
+
646
+ - [ ] **Create production app** — Separate from development
647
+ - [ ] **Configure webhooks** — If using server-side events
648
+ - [ ] **Set up push notifications** — APNs certificate uploaded
649
+ - [ ] **Enable required extensions** — Only what you need
650
+ - [ ] **Configure AI features** — If using AI capabilities
651
+ - [ ] **Review rate limits** — Understand your plan limits
652
+ - [ ] **Set up monitoring** — Enable analytics and logging
653
+
654
+ ### Server Configuration
655
+
656
+ - [ ] **Secure API keys** — Store in environment variables
657
+ - [ ] **Implement rate limiting** — Prevent abuse
658
+ - [ ] **Add request validation** — Validate all inputs
659
+ - [ ] **Set up logging** — Monitor token generation
660
+ - [ ] **Configure CORS** — If using web clients too
661
+ - [ ] **Test error scenarios** — Handle CometChat API failures
662
+
663
+ ---
664
+
665
+ ## 8. Monitoring and Analytics
666
+
667
+ ### Track CometChat Events
668
+
669
+ ```swift
670
+ // Listen for connection state
671
+ CometChat.addConnectionListener("connection-listener", self)
672
+
673
+ extension YourClass: CometChatConnectionDelegate {
674
+ func connected() {
675
+ Analytics.track("cometchat_connected")
676
+ }
677
+
678
+ func connecting() {
679
+ Analytics.track("cometchat_connecting")
680
+ }
681
+
682
+ func disconnected() {
683
+ Analytics.track("cometchat_disconnected")
684
+ }
685
+ }
686
+ ```
687
+
688
+ ### Track Message Events
689
+
690
+ ```swift
691
+ class AnalyticsListener: CometChatMessageEventListener {
692
+
693
+ func ccMessageSent(message: BaseMessage, status: MessageStatus) {
694
+ if status == .success {
695
+ Analytics.track("message_sent", properties: [
696
+ "type": message.messageType.rawValue,
697
+ "receiver_type": message.receiverType.rawValue
698
+ ])
699
+ }
700
+ }
701
+ }
702
+
703
+ CometChatMessageEvents.addListener("analytics", AnalyticsListener())
704
+ ```
705
+
706
+ ---
707
+
708
+ ## 9. Common Production Issues
709
+
710
+ | Issue | Cause | Solution |
711
+ |---|---|---|
712
+ | "User not found" | User not created in CometChat | Create user via REST API before login |
713
+ | "Invalid auth token" | Token expired or malformed | Generate new token from server |
714
+ | "Rate limit exceeded" | Too many API calls | Implement caching and rate limiting |
715
+ | Push not working | Certificate mismatch | Verify APNs cert matches environment |
716
+ | Calls failing | Missing SDK or permissions | Add CometChatCallsSDK and permissions |
717
+
718
+ ---
719
+
720
+ ## Summary
721
+
722
+ **Development → Production Migration:**
723
+
724
+ 1. Remove Auth Key from iOS app
725
+ 2. Create server endpoint for token generation
726
+ 3. Update iOS app to fetch tokens from your server
727
+ 4. Create users in CometChat when they register
728
+ 5. Test thoroughly before release
729
+ 6. Monitor and handle errors gracefully
730
+