Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> iOS

Tạo Unique ID thiết bị cho iPhone/iPad bằng Swift

UDID truyền thống bị deprecated từ iOS 5. Dùng UIDevice.current.identifierForVendor (UUID per vendor).

override func viewDidLoad() {
  super.viewDidLoad()
  guard let deviceID = UIDevice.current.identifierForVendor?.uuidString else { return }
  print(deviceID)  // ví dụ: 7ABAB8B5-E805-437F-9D6C-5448BB19AEA5
}

Giá trị này đồng nhất cho tất cả app của cùng một developer trên cùng thiết bị.