API compatibility
Platform-specific APIs
Log viewer
Android/Kotlin (Compose):
@Composable
fun MobileIdSdk.createLogView()
iOS/Swift (UIKit):
fun MobileIdSdk.createLogViewController(): UIViewController
Usage:
- Android: Use directly in Compose hierarchy
- iOS: Wrap in
UIViewControllerRepresentablefor SwiftUI
Using SDK from Swift/Objective C
Byte array conversion:
extension Array where Element == UInt8 {
func toKotlinByteArray() -> KotlinByteArray {
let data = Data(self)
return KotlinByteArray(size: Int32(data.count)) { index in
return Int8(bitPattern: data[Int(truncating: index)])
}
}
}
extension KotlinByteArray {
func toSwiftArray() -> [UInt8] {
var array = [UInt8]()
for i in 0..<size {
array.append(UInt8(bitPattern: get(index: i)))
}
return array
}
}
Accessing object from Swift/Objective C:
let states = AvailabilityStates.shared
let okState = states.OK
let credential = Credential.Companion().create(
projectKey: projectKey,
credentialId: "user_001"
)
Threading & coroutines
All SDK methods are suspend functions
Kotlin:
// Must call from coroutine scope
lifecycleScope.launch {
sdk.requestPermissions()
sdk.sendLogs()
sdk.openPermissionSettings()
}
Swift: Suspend functions become async
// Use with await in async context
Task {
try await sdk.requestPermissions()
try await sdk.sendLogs()
try await sdk.openPermissionSettings()
}
Callbacks run on coroutine scope
Kotlin: Callbacks use Dispatchers.Default
sdk.onAvailabilityChange = { availability ->
// This runs on background thread
// Update UI on main thread:
withContext(Dispatchers.Main) {
updateUI(availability)
}
}
Swift: Callbacks run on background queue
sdk.onAvailabilityChange = { availability in
// This runs on background queue
// Update UI on main queue:
DispatchQueue.main.async {
self.updateUI(availability)
}
}
Platform dispatcher usage
SDK uses appropriate dispatchers:
Dispatchers.Default: Background workDispatchers.Main: Permission requests (requires Activity context)Dispatchers.IO: File I/O, network