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.

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.