Skip to main content

iOS - Access User Info

note

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:

User Token
let q2UserToken = moduleDataSource?.user?.token
note

You can use this token can be used to make authenticated API calls from your module.

OAuth ID Token

New in Mobile SDK iOS 26.4.0

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:

OAuth ID Token
let idToken = moduleDataSource?.oAuth?.idToken
note

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:

User Name
let q2UserName = moduleDataSource?.user?.username

User Identifier

Get the unique identifier for the authenticated user:

User Identifier
let q2UserIdentifier = moduleDataSource?.user?.identifier

Push Notification Status

Determine whether push notifications are enabled for the authenticated user:

Push Notification Status
let isPushEnabled = moduleDataSource?.user?.isPushEnabled ?? false
note

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:

Conditional UI Display
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:

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()
}
}
tip

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.