iOS - Q2 Lifecycle Module
note
To receive Q2 lifecycle events, a proper implementation of the Q2LifecycleModule
protocol is required. Q2MobileCore will interact with your module for various Q2-specific
lifecycle events.
The Q2LifecycleModule
interface is used when creating a module that needs to respond to
Q2-specific lifecycle events. This module provides callbacks for various authentication
and navigation states including login, logout, and landing page navigation.
Q2 Lifecycle Events
The module receives notifications for the following events:
- When username was set by the user using the native login
- Allows module to determine if the provided username should login into the app
- Notifies user did login with success
- Notifies user did fail to login with provided exception
- Notifies that the app successfully navigated to the initial landing page after a login
- Notifies user did logout from the app
Implementation
Implementing a Q2LifecycleModule
is straightforward—create an NSObject class conforming
to the Q2LifecycleModule protocol requirements.
Sample Q2LifecycleModule Implementation
import Q2ModuleInterface
class CustomQ2LifecycleModule: Q2LifecycleModule {
var moduleDelegate: ModuleDelegate?
var moduleDataSource: ModuleDataSource?
func userDidSet(username: String) {
print("CustomQ2LifecycleModule: userDidSet\(username)")
}
// Note: This is internal to Q2 Mobile App.
func userShouldLogin(withUsername: String) -> Bool? {
print("CustomQ2LifecycleModule: userShouldLogin\(withUsername)")
return nil
}
func userDidLogin(attributes: [String: Any]?) {
print("CustomQ2LifecycleModule: userDidLogin\(attributes ?? [:])")
}
func userFailedLogin(error: Error?, attributes: [String: Any]?) {
print("CustomQ2LifecycleModule: userFailedLogin - error: \(String(describing: error)) - attributes: \(attributes ?? [:])")
}
func appDidHitLandingPage() {
print("CustomQ2LifecycleModule: appDidHitLandingPage")
}
func userDidLogout(attributes: [String: Any]?) {
print("CustomQ2LifecycleModule: userDidLogout\(attributes ?? [:])")
}
func log(_ message: String, level: LogLevel) {
// no-op
}
func logEvent(_ name: String, attributes: [String: Any]?) {
// no-op
}
func logError(error: Error, attributes: [String: Any]?) {
// no-op
}
}