iOS - Access User Info
Modules conforming to the Module interface can access an instance of ModuleDataSource
via the moduleDataSource property.
User Token
You can access the user's authentication token using:
let q2UserToken = moduleDataSource?.user?.token
You can use this token can be used to make authenticated API calls from your module.
OAuth ID Token
OAuth ID token access through moduleDataSource?.oAuth?.idToken is available starting in
26.4.0.
You can access the user's IDP ID token, when available, using:
let idToken = moduleDataSource?.oAuth?.idToken
moduleDataSource?.oAuth is available only when the active authentication module supports
IDP-based authentication and exposes an ID token.
User Name
Retrieve the username associated with the authenticated session:
let q2UserName = moduleDataSource?.user?.username
User Identifier
Get the unique identifier for the authenticated user:
let q2UserIdentifier = moduleDataSource?.user?.identifier
Push Notification Status
Determine whether push notifications are enabled for the authenticated user:
let isPushEnabled = moduleDataSource?.user?.isPushEnabled ?? false
The property represents the user's preference for push notifications within the Q2 system, not the OS-level app permission. This allows modules to make informed decisions about push-related functionality and UI.
Usage Examples
Check push status to conditionally display UI elements:
if let user = moduleDataSource?.user, user.isPushEnabled {
// Show push notification settings or related features
showPushNotificationSettings()
} else {
// Hide push-related features or show enrollment prompt
hidePushNotificationFeatures()
}
Use push status for feature availability:
func configurePushFeatures() {
guard let user = moduleDataSource?.user else { return }
if user.isPushEnabled {
// Enable push-dependent features
enableAlertNotifications()
enableSecurityNotifications()
showPushPreferences()
} else {
// Disable or hide push-dependent features
disablePushFeatures()
showPushEnrollmentPrompt()
}
}
Use this property to create a more personalized user experience by showing relevant push notification options only when the user has opted in to receive push notifications.