User Device Management (UDM)
The User Device Management (UDM) module provides functionality to manage and track user devices, including registration, monitoring, and removal of devices.
Table of Contents
registerDevice
getLinkDevices
getLinkDevice
updateLastOnline
updateDeviceName
removeDevice
getLinkDevicesHistory
Methods
registerDevice
Registers a new device with the system.
Returns: A LinkDevice
object containing the registered device information.
Throws: An error if registration fails or device identifier cannot be retrieved.
Example:
func main() async {
do {
let udmRepository = UDMRepositoryImpl(api: UDMNetworkImpl(client: NetworkClient()))
let device = try await udmRepository.registerDevice()
print("Registered device: \(device)")
} catch {
print("Error registering device: \(error)")
}
}
getLinkDevices
Retrieves a list of all linked devices for the current user.
Returns: An array of LinkDevice
objects.
Throws: An error if the fetch fails.
Example:
func main() async {
do {
let udmRepository = UDMRepositoryImpl(api: UDMNetworkImpl(client: NetworkClient()))
let devices = try await udmRepository.getLinkDevices()
print("Linked devices: \(devices)")
} catch {
print("Error fetching linked devices: \(error)")
}
}
getLinkDevice
Retrieves details of a specific linked device.
Parameters:
uniqueId
: The unique identifier of the device
Returns: A LinkDevice
object containing the device details.
Throws: An error if the fetch fails.
Example:
func main() async {
do {
let udmRepository = UDMRepositoryImpl(api: UDMNetworkImpl(client: NetworkClient()))
let device = try await udmRepository.getLinkDevice(uniqueId: "device_unique_id")
print("Device details: \(device)")
} catch {
print("Error fetching device details: \(error)")
}
}
updateLastOnline
Updates the last online timestamp for a specific device.
Parameters:
uniqueId
: The unique identifier of the device
Throws: An error if the update fails.
Example:
func main() async {
do {
let udmRepository = UDMRepositoryImpl(api: UDMNetworkImpl(client: NetworkClient()))
try await udmRepository.updateLastOnline(uniqueId: "device_unique_id")
print("Last online timestamp updated successfully")
} catch {
print("Error updating last online timestamp: \(error)")
}
}
updateDeviceName
Updates the display name of a specific device.
Parameters:
uniqueId
: The unique identifier of the devicename
: The new name for the device
Throws: An error if the update fails.
Example:
func main() async {
do {
let udmRepository = UDMRepositoryImpl(api: UDMNetworkImpl(client: NetworkClient()))
try await udmRepository.updateDeviceName(uniqueId: "device_unique_id", name: "New Device Name")
print("Device name updated successfully")
} catch {
print("Error updating device name: \(error)")
}
}
removeDevice
Removes a device from the linked devices list.
Parameters:
uniqueId
: The unique identifier of the device
Throws: An error if the removal fails.
Example:
func main() async {
do {
let udmRepository = UDMRepositoryImpl(api: UDMNetworkImpl(client: NetworkClient()))
try await udmRepository.removeDevice(uniqueId: "device_unique_id")
print("Device removed successfully")
} catch {
print("Error removing device: \(error)")
}
}
getLinkDevicesHistory
Retrieves the history of device linking and unlinking events.
Returns: An array of LinkDevicesHistory
objects.
Throws: An error if the fetch fails.
Example:
func main() async {
do {
let udmRepository = UDMRepositoryImpl(api: UDMNetworkImpl(client: NetworkClient()))
let history = try await udmRepository.getLinkDevicesHistory()
print("Device history: \(history)")
} catch {
print("Error fetching device history: \(error)")
}
}
Complete Example
Here's a complete example of how to use the UDM features:
// Initialize the repository
let networkClient = NetworkClient()
let udmNetwork = UDMNetworkImpl(client: networkClient)
let udmRepository = UDMRepositoryImpl(api: udmNetwork)
// Register a new device
Task {
do {
let device = try await udmRepository.registerDevice()
print("Registered device: \(device)")
// Get all linked devices
let devices = try await udmRepository.getLinkDevices()
print("All linked devices: \(devices)")
// Update device name
try await udmRepository.updateDeviceName(uniqueId: device.uniqueId, name: "New Device Name")
print("Device name updated")
// Update last online timestamp
try await udmRepository.updateLastOnline(uniqueId: device.uniqueId)
print("Last online timestamp updated")
// Get device history
let history = try await udmRepository.getLinkDevicesHistory()
print("Device history: \(history)")
// Remove device
try await udmRepository.removeDevice(uniqueId: device.uniqueId)
print("Device removed successfully")
} catch {
print("Error: \(error)")
}
}
Last updated