Mobile ID SDK advanced topics
Trigger authorization
Implement custom logic to control whether a trigger is allowed.
val credential = Credential.create(
projectKey = projectKey,
credentialId = "employee_001",
onTrigger = {
// Return true to allow, false to deny
val isAllowed = checkUserPermissions()
if (isAllowed) {
logTriggerEvent("Trigger allowed")
true
} else {
logTriggerEvent("Trigger denied")
showToast("Access denied")
false
}
}
)
Use cases:
- Time-based access (only allow during work hours)
- Location-based access (geofencing)
- User confirmation (require PIN or biometric)
- Rate limiting (prevent rapid repeated triggers)
Example: Time-based authorization
onTrigger = {
val currentHour = LocalTime.now().hour
val isWorkingHours = currentHour in 8..18
if (!isWorkingHours) {
showDialog("Access only allowed during work hours (8:00-18:00)")
}
isWorkingHours
}
Example: User confirmation
onTrigger = {
var allowed = false
// Show confirmation dialog (must be done on main thread)
withContext(Dispatchers.Main) {
allowed = showConfirmationDialog("Open door?")
}
allowed
}
Background operation (iOS)
iOS supports background BLE peripheral mode with limitations.
Requirements:
bluetooth-peripheralinUIBackgroundModes- App must be launched at least once
- Limited processing time in background
Limitations:
- Advertising slower in background
- CPU time limited
- May be suspended if inactive too long
Best practices:
// Keep credential active even when app backgrounded
class AppDelegate: UIResponder, UIApplicationDelegate {
let sdk = MobileIdSdk()
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialize credential early
setupCredential()
return true
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Credential remains active in background
// BLE advertising continues
}
private func setupCredential() {
// Load and activate credential
if let credential = loadSavedCredential() {
sdk.credentials = [credential]
}
}
}
Battery considerations:
- BLE advertising consumes battery
- Background operation increases consumption
- Consider allowing users to disable background operation
Statistics collection (optional)
By default, anonymous usage statistics are collected and submitted to BALTECH.
Using the command sdk.disableStatistics(), you can disable statistics collection and submission.
What's collected if statistics are enabled:
- Connection attempts
- Success/failure rates
- RSSI (signal strength) distribution
- BLE state changes
What's NOT collected:
- User identity
- Credential IDs
- Actual access events
- Location data
Privacy considerations:
- Statistics are anonymous
- No personally identifiable information
- Optional - disabled if not configured
- Best-effort - failures don't affect SDK operation