一、swift部分
1.设备名称
UIDevice.current.name
2.设备类型
UIDevice.current.model
3.系统名称
UIDevice.current.systemName
4.系统版本
UIDevice.current.systemVersion
5.屏幕分辨率
"\(Int(UIScreen.main.scale * UIScreen.main.bounds.width)) x \(Int(UIScreen.main.scale * UIScreen.main.bounds.height))"
6.是否支持多线程
UIDevice.current.isMultitaskingSupported
7.操作系统构建号
let index = ProcessInfo.processInfo.operatingSystemVersionString.firstIndex(of: "(")
let str = ProcessInfo.processInfo.operatingSystemVersionString[index!...]
let str2 = (str as NSString).substring(with: NSMakeRange(1, String(str).count-2))
8.获取UUID
UIDevice.current.identifierForVendor?.uuidString
9.获取idfa
ASIdentifierManager.shared().advertisingIdentifier.uuidString
10.获取亮度
UIScreen.main.brightness
11.获取手机位置
switch UIDevice.current.orientation {
case .portrait:
return "上"
case .portraitUpsideDown:
return "下"
case .landscapeLeft:
return "左"
case .landscapeRight:
return "右"
case .faceUp:
return "屏幕向上"
case .faceDown:
return "屏幕向下"
default:
return "未知"
}
12.是否正在接近
UIDevice.current.proximityState ? "接近" : "远离"
13.获取手机电池状态
UIDevice.current.isBatteryMonitoringEnabled = true
switch UIDevice.current.batteryState {
case .charging:
return "正在充电"
case .unplugged:
return "未充电"
case .full:
return "已充满"
default:
return "未知"
}
14.获取电池电量
"\(Int(UIDevice.current.batteryLevel * 100))%"
15.获取CPU数量
"\(ProcessInfo.processInfo.activeProcessorCount)"
16.darwinMachine
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
return identifier
17.darwinVersion
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.version)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
return identifier
18.darwinSysname
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.sysname)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
return identifier
19.darwinNodename
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.nodename)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
return identifier
20.darwinRelease
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.release)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
return identifier
21.获取WiFi名称
let interfaces = CNCopySupportedInterfaces()
var ssid = "未知"
if interfaces != nil {
let interfacesArray = CFBridgingRetain(interfaces) as! Array<AnyObject>
if interfacesArray.count > 0 {
let interfaceName = interfacesArray[0] as! CFString
let ussafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
if (ussafeInterfaceData != nil) {
let interfaceData = ussafeInterfaceData as! Dictionary<String, Any>
ssid = interfaceData["SSID"]! as! String
}
}
}
return ssid
22.获取WiFi IP
var ifaddr : UnsafeMutablePointer<ifaddrs>? = nil
if getifaddrs(&ifaddr) == 0 {
var ptr = ifaddr
while (ptr != nil) {
if let ifa_name = String(validatingUTF8:ptr!.pointee.ifa_name), ifa_name == "en0" {
let flags = Int32(ptr!.pointee.ifa_flags)
var addr = ptr!.pointee.ifa_addr.pointee
if (flags & (IFF_UP|IFF_RUNNING|IFF_LOOPBACK)) == (IFF_UP|IFF_RUNNING) {
if addr.sa_family == UInt8(AF_INET) || addr.sa_family == UInt8(AF_INET6) {
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
if (getnameinfo(&addr, socklen_t(addr.sa_len), &hostname, socklen_t(hostname.count),nil, socklen_t(0), NI_NUMERICHOST) == 0) {
if let address = String(validatingUTF8:hostname) {
return address
}
}
}
}
}
ptr = ptr!.pointee.ifa_next
}
freeifaddrs(ifaddr)
}
return "未知"
23.Wifi Mac
let interfaces = CNCopySupportedInterfaces()
var bssid = "未知"
if interfaces != nil {
let interfacesArray = CFBridgingRetain(interfaces) as! Array<AnyObject>
if interfacesArray.count > 0 {
let interfaceName = interfacesArray[0] as! CFString
let ussafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
if (ussafeInterfaceData != nil) {
let interfaceData = ussafeInterfaceData as! Dictionary<String, Any>
bssid = interfaceData["BSSID"]! as! String
}
}
}
return bssid$
想要获取WiFi信息,必须打开这个开关
24.是否支持VoIP
CTTelephonyNetworkInfo().subscriberCellularProvider?.allowsVOIP == true ? "支持" : "不支持"
26.获取WiFi上传和下载所用的流量
var ifaddr : UnsafeMutablePointer<ifaddrs>? = nil
if getifaddrs(&ifaddr) == 0 {
var ptr = ifaddr
var totalSend: UInt64 = 0
var totalReceived: UInt64 = 0
while (ptr != nil) {
let addr = ptr!.pointee.ifa_addr.pointee
if addr.sa_family == UInt8(AF_LINK),let ifa_name = String(validatingUTF8:ptr!.pointee.ifa_name) {
if ifa_name.h