MoEngageSDKCore
@objc
public class MoEngageSDKCore : NSObject
-
Declaration
Swift
@objc public static let sharedInstance: MoEngageSDKCore
-
Register the user
Declaration
Swift
@objc public func registerUser(data: String, completionHandler: @escaping UserRegistrationHandler)Parameters
dataJWT token
completionHandlerreturns the status of registration data
-
Register the user for Secondary instance
Declaration
Swift
@objc public func registerUser(data: String, appId: String? = nil, completionHandler: @escaping UserRegistrationHandler)Parameters
dataJWT token
appIdMoEngage Account identifier
completionHandlerreturns the status of registration data
-
UnRegister the User
Note
This API should be called only if user is registered successfully at some point using registerUserDeclaration
Swift
@objc public func unregisterUser(data: String, completionHandler: @escaping UserRegistrationHandler)Parameters
dataJWT token
completionHandlerreturns the status of Unregistration data
-
UnRegister the User for Secondary instance
Note
This API should be called only if user is registered successfully at some point using registerUserDeclaration
Swift
@objc public func unregisterUser(data: String, appId: String? = nil, completionHandler: @escaping UserRegistrationHandler)Parameters
dataJWT token
appIdMoEngage Account identifier
completionHandlerreturns the status of Unregistration data
-
Check if User has registered
Declaration
Swift
@objc public func getUserRegistrationStatus(completionHandler: @escaping UserRegistrationStatusHandler)Parameters
completionHandlertrue if user is registered else false
-
Check if User has registered for Secondary instance
Declaration
Swift
@objc public func getUserRegistrationStatus(forAppId appId: String? = nil, completionHandler: @escaping UserRegistrationStatusHandler)Parameters
appIdMoEngage Account identifier
completionHandlertrue if user is registered else false
-
Fetches unique ID generated by the MoEngage SDK.
Declaration
Swift
@objc public func getMoEngageDeviceId(completionHandler: @escaping UserInfoHandler)Parameters
completionHandlerreturns UUID generated by the MoEngage SDK
-
Fetches unique ID generated by the MoEngage SDK for Secondary instance
Declaration
Swift
@objc public func getMoEngageDeviceId(appId: String? = nil, completionHandler: @escaping UserInfoHandler)Parameters
appIdMoEngage Account identifier
completionHandlerreturns UUID generated by the MoEngage SDK
-
API to enable the common logs which are not specific to any AppId.
Declaration
Swift
@objc public func enableAllLogs() -
API to disable the common logs which are not specific to any AppId.
Declaration
Swift
@objc public func disableAllLogs() -
Disable throwing exception to application in debug build to avoid application crashes.
Note
By default the exception logger will take log status for the given session. Disabling logger is only applicable till process is alive in next process you again need to disable exception logger. So, call this function before SDK Initialisation to avoid exception throwing to application in debug build.Declaration
Swift
@objc public func disableIntegrationValidator() -
Pass authentication details for authentication
This method allows you to provide authentication details to the MoEngage SDK for secure API communication. The SDK will use these details to authenticate subsequent network requests while tracking data. The details need to be passed after SDK is initialized.
Usage Example
// JWT Authentication let jwtDetails = MoEngageJwtAuthenticationDetails( token: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", identifier: "user123" ) MoEngageSDKCore.sharedInstance.passAuthenticationDetails(jwtDetails, workspaceId: "your_workspace_id") // For default instance MoEngageSDKCore.sharedInstance.passAuthenticationDetails(jwtDetails)Authentication Flow
- Authentication details are stored securely for the specified workspace
- All subsequent API calls tracking data will include the authentication token
- If authentication fails, registered error listeners will be notified
Thread Safety
- This method is thread-safe and can be called from any thread
- Authentication details are processed asynchronously
- Multiple calls with different details will update the authentication
Error Handling
- Register an authentication error listener to handle authentication failures
- Use
registerAuthenticationListener(_:workspaceId:)to receive error notifications Authentication errors include detailed information about failure reasons
Declaration
Swift
@available(iOSApplicationExtension, unavailable) func passAuthenticationDetails(_ details: MoEngageAuthenticationDetails, workspaceId: String?)Parameters
detailsThe authentication details containing token and user identifier
workspaceIdMoEngage Account identifier (optional, uses default instance if nil)
-
Pass authentication details for authentication in default instance.
Convenience method that passes authentication details to the default SDK instance (workspace ID = nil). This is equivalent to calling
passAuthenticationDetails(_:workspaceId:)with a nil workspace ID.Usage Example
let jwtDetails = MoEngageJwtAuthenticationDetails( token: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", identifier: "user123" ) MoEngageSDKCore.sharedInstance.passAuthenticationDetails(jwtDetails)See also
passAuthenticationDetails(_:workspaceId:)for detailed documentationDeclaration
Swift
@available(iOSApplicationExtension, unavailable) func passAuthenticationDetails(_ details: MoEngageAuthenticationDetails)Parameters
detailsThe authentication details containing token and user identifier
-
Register a listener for authentication errors.
This method allows you to register a listener that will be notified when authentication errors occur during network requests. The listener will receive detailed error information including error codes, messages, and account metadata. The listner needs to be registered after SDK is initialized and before passing authentication details.
Usage Example
class MyAuthListener: MoEngageAuthenticationError.Listener { func onError(_ error: MoEngageAuthenticationError) { if let jwtError = error as? MoEngageJwtAuthenticationError { print("JWT Error: \(jwtError.details.code.rawValue) - \(jwtError.details.message ?? "No message")") // Handle JWT error appropriately (refresh token etc.) } } } let listener = MyAuthListener() MoEngageSDKCore.sharedInstance.registerAuthenticationListener(listener, workspaceId: "your_workspace_id")Thread Safety
- Listener registration is thread-safe
- Error callbacks are delivered serially
Ensure your listener implementation is thread-safe
Note
The listener is held with a strong reference. Use your
UIApplicationDelegateclass or any other class instance that is shared globally, to not miss any callbacks.Declaration
Swift
@available(iOSApplicationExtension, unavailable) func registerAuthenticationListener(_ listener: MoEngageAuthenticationError.Listener, workspaceId: String?)Parameters
listenerThe listener object that will receive authentication error callbacks
workspaceIdMoEngage Account identifier (optional, uses default instance if nil)
-
Register a listener for authentication errors in the default instance.
Convenience method that registers an authentication error listener for the default SDK instance (workspace ID = nil).
See also
registerAuthenticationListener(listener:workspaceId:)for detailed documentationDeclaration
Swift
@available(iOSApplicationExtension, unavailable) func registerAuthenticationListener(_ listener: MoEngageAuthenticationError.Listener)Parameters
listenerThe listener object that will receive authentication error callbacks