This section provides information on initialisation of the iOS SDK.
A sample application Hydra Sample App is available for testing framework integration and APIs.
To initialise the Capillary iOS SDK, perform the following:
-
Open the AppDelegate file in your Xcode project.
-
Locate the method
application(_:didFinishLaunchingWithOptions:)
. If not available, use the below code and create the method.optional func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil ) -> Bool
-
Add the below code to the method and create the HydraCore instance. You need to create an instance of the SDK for each application separately.
static public func generate(with configuration: ConfigurationGenerator, geoData: GeographicDataGenerator? = nil, supportsPushNotifications: Bool = false, deviceScreenInfo: DeviceScreenInfo? = nil) throws -> Hydra
The table below provides an overview of the parameters, their corresponding types, descriptions, and whether they are mandatory or optional.
Parameter Type Description Mandatory/Optional HydraConfiguration ConfigurationGenerator An object of class conforming to ConfigurationGenerator protocol Mandatory GeoData GeographicDataGenerator User's geographic details Optional supportsPushNotifications Bool Device's push notification settings Mandatory DeviceScreenInfo DeviceScreenInfo Device screen size Optional -
Retrieve the parameter values for the required configuration (HydraConfiguration, GeoData, and DeviceScreenInfo). Use the below code snippets:
-
HydraConfiguration (Mandatory)
public protocol ConfigurationGenerator { var accountID: String {get set} var customerId: String {get set} var server: ServerConfig {get set}
Parameter Type Description Mandatory/Optional accountID String Account ID of partner Mandatory customerId String Phone/email/external ID Mandatory server ServerConfig Server configuration Optional -
GeoData(Optional)
This is optional and needs to be passed only if the below values have to be sent to the SDK.
public protocol GeographicDataGenerator { var country: String? {get set} var city: String? {get set} var countryCode: String? {get set} var timeZone: String {get set} }
-
DeviceScreenInfo(Optional)
This is optional and needs to be passed only if the below values have to be sent to the SDK.
public protocol DeviceScreenInfoGenerator { var screenWidth: Int {get set} var screenHeight: Int {get set} }
Parameter Type Description Mandatory/Optional screenWidth Int Device screen width Mandatory screenHeight Int Device screen height Mandatory
-
-
Initialise the SDK. See the below example:
do { let config = HydraConfiguration(accountID: "account-id", customerId: "customer-id", server: .server1) let geoData = GeoData(country: "country", countryCode: "country-code", city: "city", timeZone: "timezone") let deviceInfo = DeviceScreenInfo(screenHeight: 00, screenWidth: 00) let supportsPushNotifications = true Hydra.generate(with: config, geoData: geoData, supportsPushNotifications: supportsPushNotifications, deviceScreenInfo: deviceInfo) } catch let error { print("Failed to initialise Hydra SDK") }
-
Placeholder
The SDK also allows to set of additional parameters at a later stage, after the SDK has been initialized. You can set the following parameters:
- Customer Id
- Device Token
- InterfaceId/FCM Token
- Notification support ie Users notification settings status
Updating customer Id
To set a customer Id or to update a customer ID, use the below API. Whenever the customer Id changes in the app, the same must be updated in the SDK.
public func update(customerID id:String)
Example:
hydraCore.update(customerID: "customer-id")
Updating device token
You need to update the device's push token to ensure continued receipt of push notifications. use the below API:
public func update(deviceToken id: String)
Example:
hydraCore.update(deviceToken: "device-token")
If you are using Firebase for receiving push notifications, use the below API:
public func update((interfaceID id: String)
Updating interfaceId/FCM token
For the application to receive remote notifications properly, you must update the Firebase Cloud Messaging (FCM) token whenever necessary. Use the below API:
public func update(interfaceID id: String)
Example:
hydraCore.update(interfaceID: "FCM-Token")
Updating notification support
You can enable or disable the support for notifications in your application. Use the below API:
public func update(notificationSupport status: Bool
Example:
hydraCore.update(notificationSupport: true)
Updating log level
Capillary SDK has a logging mechanism that enables the application to view all the SDK logs. The SDK logs statements at various levels and allows the application to determine the extent of logs it wishes to observe. The application can print records as per its requirements, enabling efficient monitoring and debugging capabilities.
Level | Description |
---|---|
critical | Critical messages indicate a serious problem and may result in the failure of the application |
error | Error messages indicate a problem that has occurred, but the application may continue to run. |
info | Info messages provide general information about the application's operation. |
debug | Debug messages provide detailed information about the application's operation, which can be useful for debugging problems. |
verbose | Verbose messages provide extremely detailed information about the application's operation, which can be useful for troubleshooting problems. |
API:
public func updateLogLevel(level: LogLevel)
By default, the
updateLogLevel
is set asverbose
.
Example:
hydraCore.updateLogLevel(level: .critical)