iOS cung cấp lớp UIDevice chứa tất cả thông tin về iPhone không vi phạm luật bảo mật của Apple.
Sử dụng UIDevice có thể truy cập thông tin như:
- UIDevice.current.localizedModel - trả về phiên bản bản địa hóa của model
- UIDevice.current.model - trả về model thiết bị hiện tại, ví dụ: "iPhone", "iPod touch"
- UIDevice.current.name - trả về tên thiết bị hiện tại, ví dụ: "My iPhone"
- UIDevice.current.systemName - trả về tên hệ thống, ví dụ: "iOS"
- UIDevice.current.systemVersion - trả về phiên bản hệ thống, ví dụ: "4.0"
- UIDevice.current.batteryLevel - trả về mức pin, nếu 0-1 trả về giá trị, nếu trạng thái UIDeviceBatteryStateUnknown trả về -1.0
- UIDevice.current.batteryState - trả về trạng thái pin, 4 giá trị theo API Apple
public enum BatteryState : Int { case unknown case unplugged case charging case full }
Bạn có thể viết mã trên trong viewDidLoad của View Controller và in ra để xem kết quả.
print(UIDevice.current.model) print(UIDevice.current.localizedModel) print(UIDevice.current.systemVersion)
Kết quả chạy trên trình mô phỏng iPhone 7 plus:
iPhone iPhone 12.0
Đây là kết quả và ví dụ cách dùng mã trên.
