The ContactsManager SDK provides a comprehensive API through the ContactsService class. Here’s how to access and use the service:
Copy
// Access the shared instancelet service = ContactsService.shared// Check initialization statuslet isInitialized = service.isInitialized// Get current statelet state = service.currentState
The SDK provides comprehensive error handling across all platforms:
Copy
do { try await ContactsService.shared.initialize( withAPIKey: "your-api-key", token: "user-auth-token", userInfo: userInfo )} catch let error as ContactsServiceError { switch error { case .invalidAPIKey: print("Invalid API key") case .apiKeyValidationFailed(let reason): print("API key validation failed: \(reason)") case .networkError(let error): print("Network error: \(error.localizedDescription)") case .initializationFailed(let error): print("Initialization failed: \(error.localizedDescription)") case .databaseError(let error): print("Database error: \(error.localizedDescription)") case .notInitialized: print("SDK not initialized") case .contactsAccessDenied: print("Contacts access denied") case .userNotAuthenticated: print("User not authenticated") case .invalidUserInfo(let reason): print("Invalid user info: \(reason)") case .customError(let message): print("Error: \(message)") }}
Important: Secure Your Users’ DataServer-side token generation is required to ensure the security of your users’ contact data. By handling authentication through your server, you establish a two-factor security model:
API Key verification
Server-generated token validation
This approach ensures that only authenticated devices with valid server-issued tokens can access your users’ contact data. Your server maintains complete control over data access, allowing you to:
Authenticate users through your existing auth system
Immediately revoke access when needed
Protect against unauthorized data access
Monitor and audit access patterns
See the server setup section in the Quickstart guide for implementation details.