Set/Get Device Information
Once logged in to the application, you can get the device information and update it. Set / Get Device information flows involve the events detailed in the respective tables.
iOS/Swift
For Swift, you can use the following code snippets, where the completion handler handles the response to the event:
Triggering GetDeviceInformation Event(Swift)
func triggerGetDeviceInformationEvent(
userIdentifier: KsUserIdentifier,
withCompletionHandler completionBlock: ((KsEvent?) -> Void)? = nil)
{
let event = KSMGetDeviceInformationEvent(
userIdentifier: userIdentifier )
masterControllerAdapter.sendEvent2MasterController(event) { (event) in
// Handle this result according to your requirement
completionBlock?(event)
}
}
Triggering SetDeviceName Event(Swift)
func triggerSetDeviceNameEvent(
setDeviceNameRequest: SetDeviceNameRequest,
completion: @escaping(_ result:KsEvent?) -> Void)
{
let setDeviceInfo = KSMSetDeviceNameEvent(
deviceName: setDeviceNameRequest.deviceName)
masterControllerAdapter.sendEvent2MasterController(setDeviceInfo) {
(event) in
// Handle this result according to your requirement
completion(event)
}
}
Android/Kotlin
For Kotlin, we have created dedicated methods in the MCHandler class of our example app to trigger respective events. Below are the code snippets:
Triggering GetDeviceInformation Event(Kotlin)
fun triggerGetDeviceInformationEvent(userId: String, tenantId: String) {
logDebug(
"triggering GetDeviceInformationEvent with userId => $userId && tenantId => $tenantId",
"triggerGetDeviceInformationEvent",
TAG
)
val getDeviceInformationEvent = GetDeviceInformationEvent(
UserIdentifier(tenantId, userId)
)
mcEventHandler?.postEvent(getDeviceInformationEvent)
?.then {
logDebug(
"Received deviceInfo: $it",
"triggerGetDeviceInformationEvent",
TAG
)
// handle result
}
}
Triggering SetDeviceName Event(Kotlin)
fun triggerSetDeviceNameEvent(deviceName: String) {
logDebug(
"triggering SetDeviceNameEvent with deviceName => $deviceName",
"triggerSetDeviceNameEvent",
TAG
)
val setDeviceNameEvent =
SetDeviceNameEvent(deviceName)
mcEventHandler?.postEvent(setDeviceNameEvent)?.then {
// handle result
}
}
Handling SetDeviceNameResult Event
override fun onEventReceived(eventFrameworkEvent: EventFrameworkEvent) {
showHideProgressBar(false)
super.onEventReceived(eventFrameworkEvent)
when (eventFrameworkEvent) {
is SetDeviceNameResultEvent -> {
when (eventFrameworkEvent.status) {
StatusType.OK -> {
deviceNameHandlerCallback.onDeviceNameSetSuccessful()
}
StatusType.NOT_UNIQUE -> {
launchMain {
Utils.showAlertDialog(
context = baseActivity,
text = baseActivity.getString(R.string.error_msg_unique_device_name),
clickListener = null,
title = baseActivity.getString(R.string.label_error)
)
}
}
StatusType.NOT_REACHABLE -> {
launchMain {
Utils.showAlertDialog(
context = baseActivity,
text = baseActivity.getString(
R.string.ks_ast_001_activation_useridactivationcodeview_alert_text_connectionnotestablished),
clickListener = null,
title = baseActivity.getString(R.string.label_error)
)
}
}
else -> {
launchMain {
Utils.showAlertDialog(
context = baseActivity,
text = baseActivity.getString(R.string.error_msg_device_name_change),
clickListener = null,
title = baseActivity.getString(R.string.label_error)
)
}
}
}
}
}
}