-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapi_getSystemInfo.swift
More file actions
89 lines (73 loc) · 3.07 KB
/
Copy pathapi_getSystemInfo.swift
File metadata and controls
89 lines (73 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// api_getSystemInfo.swift
// HelloSwift
//
// Created by 1 on 8/1/22.
//
import SwiftUI
struct DeviceItem: Identifiable {
let id = UUID()
let name: String
let desc: String
let value: String
}
struct api_getSystemInfo: View {
@State var DeviceInfo:[DeviceItem] = []
var body: some View {
List {
Section() {
ForEach(DeviceInfo) { item in
HStack() {
Text(item.desc)
.frame(width: 100)
Text(item.value)
.font(.body)
.lineLimit(1)
}
}
}
Button("重新获取", action: {
getDeviceInfo()
})
.frame(maxWidth: .infinity,alignment: .center)
}
.listStyle(.grouped)
.onAppear() {
getDeviceInfo()
}
.navigationTitle("设备信息")
.navigationBarTitleDisplayMode(.inline)
.modifier(navBarViewCodeAndDocs(pageType: "API",pageID: "getSystemInfo"))
}
func getDeviceInfo() {
self.DeviceInfo = []
let deviceName = UIDevice.current.name
self.DeviceInfo.append(DeviceItem(name: "name", desc: "设备名称", value: deviceName))
let deviceID = UIDevice.current.identifierForVendor?.uuidString
self.DeviceInfo.append(DeviceItem(name: "uuidString", desc: "设备ID", value: deviceID!))
let systemName = UIDevice.current.systemName
self.DeviceInfo.append(DeviceItem(name: "systemName", desc: "系统名称", value: systemName))
let systemVersion = UIDevice.current.systemVersion
self.DeviceInfo.append(DeviceItem(name: "systemVersion", desc: "系统版本", value: systemVersion))
let model = UIDevice.current.model
self.DeviceInfo.append(DeviceItem(name: "model", desc: "设备型号", value: model))
// 2022/9/25 横屏竖屏判断 存在问题,暂时屏蔽
// let isPortrait = UIDevice.current.orientation.isPortrait
// self.DeviceInfo.append(DeviceItem(name: "model", desc: "横屏", value: "\(isPortrait)"))
//
// let isLandscape = UIDevice.current.orientation.isLandscape
// self.DeviceInfo.append(DeviceItem(name: "model", desc: "竖屏", value: "\(isLandscape)"))
let screenHeight = UIScreen.main.bounds.height
self.DeviceInfo.append(DeviceItem(name: "height", desc: "屏幕高度", value: "\(screenHeight)"))
UIDevice.current.isBatteryMonitoringEnabled = true
let screenWidth = UIScreen.main.bounds.width
self.DeviceInfo.append(DeviceItem(name: "width", desc: "屏幕宽度", value: "\(screenWidth)"))
let battery = UIDevice.current.batteryLevel * 100
self.DeviceInfo.append(DeviceItem(name: "battery", desc: "电量", value: "\(battery)"))
}
}
struct api_getSystemInfo_Previews: PreviewProvider {
static var previews: some View {
api_getSystemInfo()
}
}