45 lines
1.2 KiB
Swift
45 lines
1.2 KiB
Swift
//
|
|
// UIDeviceExtensions.swift
|
|
// app
|
|
//
|
|
// Created by Sebastian Pobel on 27.01.20.
|
|
// Copyright © 2020 Marcus Handte. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
extension UIDevice {
|
|
var modelName: String {
|
|
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)))
|
|
}
|
|
if let value = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] {
|
|
return value
|
|
} else {
|
|
return identifier
|
|
}
|
|
}
|
|
|
|
var batteryStateString: String? {
|
|
UIDevice.current.isBatteryMonitoringEnabled = true
|
|
var status: Bool
|
|
switch UIDevice.current.batteryState {
|
|
case .charging:
|
|
status = true
|
|
case .full:
|
|
status = false
|
|
case .unknown:
|
|
return nil
|
|
default:
|
|
status = false
|
|
}
|
|
UIDevice.current.isBatteryMonitoringEnabled = false
|
|
return "\(status)"
|
|
}
|
|
}
|