Swift (iOS)
Installation
To integrate ConnectFramework
into your Swift project, add the SDK via Swift Package Manager (SPM) or manually include it in your project.
Swift Package Manager
In Xcode, go to File > Add Packages.
Enter the package repository URL for
ConnectFramework
.Select a version or branch and press Add Package.
Then, import the framework where needed:
import ConnectFramework
Usage
Initializing the SDK
Before making any API calls, initialize the SDK with your API key.
// Initialize the SDK with an API key
ConnectFramework.initialize(apiKey: "your_api_key_here")
User Authentication
Logging in with a Unique ID
Logs the user in with a unique ID. You can pass nil
, and a unique ID will be created automatically.
ConnectFramework.login(uniqueId: nil) { success in
if success {
print("User logged in successfully.")
} else {
print("Login failed or was cancelled.")
}
}
Logging Out
Logs the user out entirely.
ConnectFramework.logout()
Checking if User is Connected
Returns true
if the user is logged in and running the Connect.ai desktop client.
let isConnected = ConnectFramework.isConnected()
print("User is connected: \(isConnected)")
Paywall Management
Creating a Paywall
Creates and presents a new paywall. The callback receives two parameters:
success
(Bool
):true
if the user completed a purchase,false
otherwise.productId
(String?
): The product ID if a purchase occurred, otherwisenil
.
ConnectFramework.createPaywall { success, productId in
if success {
print("User purchased product: \(productId ?? "Unknown")")
} else {
print("User did not complete the purchase.")
}
}
Setting Extra JSON Data
Optional: Configures the user JSON settings used by the paywall.
let extraSettings = "{\"custom_key\": \"custom_value\"}"
ConnectFramework.setExtraJson(json: extraSettings)
Checking if User has Purchased
Returns true
if the user has already made a purchase. You should not present a paywall if this returns true
.
let hasPurchased = ConnectFramework.hasPurchased()
print("User has purchased: \(hasPurchased)")
Analytics Tracking
Logging an Event
Logs an analytics event with a category and action.
ConnectFramework.logEvent(category: "user_action", action: "button_click")
Logging an Event with Additional Data
Logs an analytics event with a category, action, label, and numerical value.
ConnectFramework.logEvent(category: "user_action", action: "purchase", label: "premium_upgrade", value: 29.99)
Last updated