> For the complete documentation index, see [llms.txt](https://cramiumlabs.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cramiumlabs.gitbook.io/docs/sdk-mpc-ios/usage-guide-for-an-mpc-wallet-app/user-device-management-udm.md).

# User Device Management (UDM)

### Table of Contents

1. registerDevice
2. getLinkDevices
3. getLinkDevice
4. updateLastOnline
5. updateDeviceName
6. removeDevice
7. 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:**

```swift
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:**

```swift
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:**

```swift
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:**

```swift
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 device
* `name`: The new name for the device

**Throws:** An error if the update fails.

**Example:**

```swift
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:**

```swift
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:**

```swift
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:

```swift
// 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)")
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cramiumlabs.gitbook.io/docs/sdk-mpc-ios/usage-guide-for-an-mpc-wallet-app/user-device-management-udm.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
