# Add a New Trusted Device

## Steps

There are 2 steps that's needed to add a new Trusted Device:&#x20;

1. [Show the QR Code](/sdk-reference/ios/ios-sdk-passwordless-login/add-a-new-trusted-device.md#step-1-show-the-qr-code-of-the-new-device) of the New Device&#x20;
2. [Scan the New Device's QR Code](/sdk-reference/ios/ios-sdk-passwordless-login/add-a-new-trusted-device.md#step-2-scanning-the-qr-code-from-a-trusted-device) using the Trusted Device

![Scan the New Device's QR Code using the Trusted Device](/files/-M4uoteieJmjnucL2sPA)

## **Step 1:  Show the QR Code of the New Device**

To show the QR Code of the new device:

Example:

```swift
class SomeUIVC: UIViewController {
  var cotter: Cotter?

  override func viewDidLoad() {
    super.viewDidLoad()

    self.cotter = Cotter(
      apiSecretKey: "588d6f67-0981-4718-899b-bcd512de1aca",
      apiKeyID: "w4FK6Zz0XIhtGY3o5biI",
      cotterURL: "https://www.cotter.app/api/v0",
      userID: "hello@example.com",
      configuration: [:]
    )
  }

  // On Button Click
  @IBAction func registerThisDeviceAsTrusted(_ sender: UIButton) {
    func callback(token:String, err: Error?) {
        if err != nil {
          print(err?.localizedDescription)
          self.textLabel.text = "Failed to register new device!"
          return
        }
        self.textLabel.text = "Successfully registered new device!"
    }

    /* Open QR Code that can be scanned from the Trusted Device. */
    self.cotter?.registerNewDevice(vc: self, cb: callback)
  }
}
```

This will open a View Controller with a QR Code that can be scanned from the Trusted Device. After registration is done, the above-defined callback function would be called.

For the above callback, a text label in the `SomeUIVC` view controller will be populated to let the user know whether registration succeeded or failed. Otherwise, if desired, the user can also perform a segue to another view controller (on success or failure) in the callback function as well.

![Different Cases of Registering a New Device as a Trusted Device](/files/-M4uozLhaNOLCw8FDkYt)

### **Case 1: Successfully registered as a Trusted Device**

Once it's scanned and registered successfully as, the View Controller will show a success image, and close after 3 seconds.

### **Case 2: The new device is still not registered as a Trusted Device after 3 minutes**

If after 3 minutes, the new device is still not registered as a Trusted Device, it will show an error message.

## **Step 2: Scanning the QR Code from a Trusted Device**

To scan the QR Code from a Trusted Device, call the function:

```swift
class SomeUIVC: UIViewController {
  var cotter: Cotter?

  override func viewDidLoad() {
    super.viewDidLoad()

    self.cotter = Cotter(
      apiSecretKey: "588d6f67-0981-4718-899b-bcd512de1aca",
      apiKeyID: "w4FK6Zz0XIhtGY3o5biI",
      cotterURL: "https://www.cotter.app/api/v0",
      userID: "hello@example.com",
      configuration: [:]
    )
  }

  // On Button Click
  @IBAction func executeScanOfOtherDevice(_ sender: UIButton) {
    /* Open a View Controller that opens the Camera to scan the
       QR Code on the other non-trusted device. We do not need 
       to pass in a callback, as the user will be redirected
       back to this view controller. */
    self.cotter?.scanNewDevice(vc: self, cb: nil)
  }
}
```

This will open a View Controller that opens the Camera. It will ask for permission to access the camera. When the QR Code is detected and scanned, it will automatically attempt to register the new device. After scanning is done, the user will be redirected back to the above `SomeUIVC` view controller.

![Scanning the New Device's QR Code from the Trusted Device](/files/-M4up2YT_AA7ImJL6wzm)

When the QR Code is detected and registered, the SDK will automatically show whether it was successful or if there's an error.

## 🎉 **You're done!**

Now you can authenticate from the new device without requiring approval.


---

# Agent Instructions: 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:

```
GET https://docs.cotter.app/sdk-reference/ios/ios-sdk-passwordless-login/add-a-new-trusted-device.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
