Testing and Debugging
This guide covers logging, diagnostics, common issues, and debugging strategies for the MOSA SDK.
Logging
Android
Enable advanced logging:
val sdk = MOSADockSDK.builder()
.setActivity(this)
.setApiKey("your-api-key")
.setUserId("user-123")
.setAdvancedLogging(true) // Enable advanced logging
.build()
View logs in Logcat:
adb logcat | grep -i "MOSADockSDK"
iOS
Logging is enabled by default. View logs in Xcode console or system logs:
// Logs are automatically output to console
// Use Xcode's console or Console.app to view
Filter logs:
log stream --predicate 'subsystem == "com.mosa.docksdk"' --level debug
Flutter
Listen to SDK logs:
mosaDockSdk.sdkLogs.listen((log) {
print('SDK Log: ${log['level']} - ${log['message']}');
});
Common Issues
Issue: NFC Not Working
Symptoms: NFC scan fails or doesn't start
Solutions:
- Check NFC is enabled in device settings
- Verify NFC permission is granted
- Ensure device supports NFC (iPhone 7+ for iOS, Android 7.0+)
- Check NFC tag is within range (~4cm)
- Verify NFC tag is valid MOSA dock tag
Issue: BLE Connection Fails
Symptoms: BLE connection fails or times out
Solutions:
- Check Bluetooth is enabled
- Verify BLE permissions are granted
- Ensure device supports BLE
- Check dock is powered on and in range
- Verify MAC address from NFC scan is correct
- Try disconnecting and reconnecting
Issue: Key Request Fails
Symptoms: requestUnlockKey() returns null or throws error
Solutions:
- Check internet connectivity
- Verify API key is valid
- Ensure user ID is correct
- Check area ID exists and is valid
- Verify session requirements are met
- Check backend API status
Issue: Dock Operation Times Out
Symptoms: Operation times out before completion
Solutions:
- Ensure dock is powered on
- Check BLE connection is stable
- Verify unlock key is not expired
- Check dock is not in use by another user
- Verify dock firmware is compatible
- Try operation again
Issue: Callbacks Not Received
Symptoms: Callbacks are not called during operations
Solutions:
- Android: Ensure callback is passed to
unlockSmartLock() - iOS: Ensure delegate is set before operation
- Flutter: Ensure event stream subscription is set up before initializing SDK
- Verify callbacks are on main thread (should be automatic)
- Check for errors in
onErrorcallback
Issue: Sync Not Working
Symptoms: Events not syncing to backend
Solutions:
- Check internet connectivity
- Verify sync is enabled
- Check pending events count:
getPendingEventsCount() - Manually trigger sync:
forceSyncNow() - Check sync errors in logs
- Verify API key is valid
Debugging Tips
Enable Verbose Logging
Enable advanced logging to see detailed SDK operations:
- Android
- iOS
- Flutter
val sdk = MOSADockSDK.builder()
.setAdvancedLogging(true)
.build()
// Logging is enabled by default
// Use Xcode console to view logs
// Listen to SDK logs
mosaDockSdk.sdkLogs.listen((log) {
print('SDK: ${log['level']} - ${log['message']}');
});
Check Device Capabilities
Always verify device capabilities before operations:
- Android
- iOS
- Flutter
if (!sdk.isBLESupported() || !sdk.isNFCSupported()) {
// Device doesn't support required features
}
if (!sdk.isBLEEnabled() || !sdk.isNFCEnabled()) {
// Features are disabled
}
if !sdk.isBLESupported() || !sdk.isNFCSupported() {
// Device doesn't support required features
}
final bleSupported = await mosaDockSdk.isBleSupported();
final nfcSupported = await mosaDockSdk.isNfcSupported();
final bleEnabled = await mosaDockSdk.isBleEnabled();
final nfcEnabled = await mosaDockSdk.isNfcEnabled();
Monitor Connection State
Monitor BLE connection state:
- Android
- iOS
- Flutter
sdk.getBleConnectionStateFlow().collect { connected ->
println("BLE Connected: $connected")
}
sdk.bleConnectionPublisher
.sink { connected in
print("BLE Connected: \(connected)")
}
mosaDockSdk.bleConnectionStateEvents.listen((event) {
print('BLE Connected: ${event.connected}');
});
Check Key Expiry
Always check key expiry before use:
- Android
- iOS
- Flutter
val isExpired = unlockKey.expiryTime <= (System.currentTimeMillis() / 1000)
if (isExpired) {
// Request new key
}
let currentTime = Int(Date().timeIntervalSince1970)
if unlockKey.expiryTime <= currentTime {
// Request new key
}
if (unlockKey.isExpired) {
// Request new key
}
Troubleshooting Checklist
Use this checklist when debugging issues:
- Device supports NFC and BLE
- NFC and BLE are enabled
- Required permissions are granted
- SDK is properly initialized
- API key is valid
- User ID is correct
- Internet connectivity available (for key requests)
- Dock is powered on and in range
- NFC tag is valid MOSA dock tag
- Unlock key is not expired
- Callbacks are properly set up
- Error callbacks are implemented
- Logs are checked for errors
Getting Help
If you're still experiencing issues:
- Check Logs: Review SDK logs for error messages
- Verify Setup: Ensure all prerequisites are met
- Test with Sample App: Try the sample app to verify SDK works
- Contact Support: See Support for help
Next Steps
- SDK Callbacks - Callback troubleshooting
- Support - Get help from support team
For platform-specific debugging, see the Platform Guides.