Device
Handles Device related requests with IMS web services. Unless otherwise specified, requests performed by this service are on the current Device.
Last updated
Handles Device related requests with IMS web services. Unless otherwise specified, requests performed by this service are on the current Device.
Last updated
To activate the current device for data collection, the following API can be used.
let service = DeviceService()
service.activate(then: { result in
switch result {
case: .success(_)
// activation successful
case: .failure(_)
// failure error
}
})
Deactivate the current device for data collection. It may be desirable to deactivate a device if the host application's user logs out, or if the user becomes inactive.
To deactivate the current device for data collection, the following API can be used.
let service = DeviceService()
service.deactivate(then: { result in
switch result {
case: .success(_)
// deactivation successful
case: .failure(_)
// failure error
}
})
In order to fetch the currentDevice
's model, the following API can be used.
let service = DeviceService()
service.fetch(then: { result in
guard !result.value.isEmpty else {
// error
return
}
completionHandler(.success(result.value))
})
To verify whether the current device is activated or to reactivate it if needed, please refer to the example below.
let service = DeviceService()
deviceService.fetch { result in
switch result {
case .success:
guard let device = result.value else {
// DEVICE DOES NOT EXIST -> IS NOT ACTIVATED -> Re-ACTIVATE
deviceService.activate(then: { result in
switch result {
case: .success(_)
// activation successful
case: .failure(_)
// failure error
}
})
return
}
guard device.isDataCollectionEnabled ?? false else {
// DEVICE IS PRESENT -> BUT NOT ACTIVATED -> Re-ACTIVATE
deviceService.activate(then: { result in
switch result {
case: .success(_)
// activation successful
case: .failure(_)
// failure error
}
})
return
}
// DEVICE IS ACTIVATED
completionHandler(.success(device))
case .failure(let error):
// HANDLE FAILURE
}
}