How can i get udid device on swift

Asked on 02/06/2025

1 search

To get the UDID of a device in Swift, you typically need to use Apple's APIs that provide access to device identifiers. However, Apple has restricted access to the UDID for privacy reasons, and it is not directly accessible in apps. Instead, you can use the identifierForVendor property of UIDevice to get a unique identifier for your app on a device. Here's a simple example in Swift:

import UIKit

if let identifierForVendor = UIDevice.current.identifierForVendor {
    print("Device Identifier: \(identifierForVendor.uuidString)")
}

This code will give you a unique identifier for the app on the device, which is different from the UDID but serves a similar purpose for app-specific identification.

If you are working with embedded devices or need to interact with hardware, you might find the session "Go small with Embedded Swift" from WWDC 2024 useful. It discusses using Swift for programming embedded devices, which might be relevant if you are working with hardware that requires unique identifiers. You can explore more about this in the session Go small with Embedded Swift (03:39).