diff --git a/CHANGELOG.md b/CHANGELOG.md index 024b296..eaa2d6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,17 @@ # Changelog -## Version 4.8.1 +## Version 4.9.0 -Releasedate: 2022-10-28 +Releasedate: TBD ```ruby -pod 'DeviceKit', '~> 4.8' +pod 'DeviceKit', '~> 4.9' ``` +### New features + +- Add ability to get current device's thermal state. ([#332](https://github.com/devicekit/DeviceKit/pull/332)) + ### Bugfixes - Fix Apple Watch Series 7 device identifier being incorrect. ([#329](https://github.com/devicekit/DeviceKit/pull/329)) diff --git a/DeviceKit.podspec b/DeviceKit.podspec index 7b3ea31..51e2ca3 100644 --- a/DeviceKit.podspec +++ b/DeviceKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'DeviceKit' - s.version = '4.8.1' + s.version = '4.9.0' s.summary = 'DeviceKit is a ยต-framework that provides a value-type replacement of UIDevice.' s.description = <<-DESC diff --git a/DeviceKit.xcodeproj/project.pbxproj b/DeviceKit.xcodeproj/project.pbxproj index f9c6496..f5c61c9 100644 --- a/DeviceKit.xcodeproj/project.pbxproj +++ b/DeviceKit.xcodeproj/project.pbxproj @@ -380,7 +380,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 4.8.1; + MARKETING_VERSION = 4.9.0; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = me.dennisweissmann.DeviceKit; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -437,7 +437,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 4.8.1; + MARKETING_VERSION = 4.9.0; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = me.dennisweissmann.DeviceKit; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Example/DeviceKitPlayground.playground/Contents.swift b/Example/DeviceKitPlayground.playground/Contents.swift index 5712e60..95d7931 100644 --- a/Example/DeviceKitPlayground.playground/Contents.swift +++ b/Example/DeviceKitPlayground.playground/Contents.swift @@ -4,7 +4,7 @@ import DeviceKit import UIKit -let device = Device() +let device = Device.current print(device) // prints, for example, "iPhone 6 Plus" @@ -52,19 +52,21 @@ if device.isOneOf(groupOfAllowedDevices) { } /// Get the Current Battery State -if device.batteryState == .full || device.batteryState >= .charging(75) { +if let batteryState = device.batteryState, + batteryState == .full || batteryState >= .charging(75) { print("Your battery is happy! ๐Ÿ˜Š") } /// Get the Current Battery Level -if device.batteryLevel >= 50 { +if device.batteryLevel ?? 0 >= 50 { // install_iOS() } else { // showError() } /// Get Low Power mode status -if device.batteryState.lowPowerMode { +if let batteryState = device.batteryState, + batteryState.lowPowerMode { print("Low Power mode is enabled! ๐Ÿ”‹") } else { print("Low Power mode is disabled! ๐Ÿ˜Š") @@ -96,3 +98,8 @@ let simulator = Device.simulator(.iPhone8Plus) let realDevice = Device.iPhone8Plus simulator.realDevice == realDevice // true realDevice.realDevice == realDevice // true + +// Get device thermal state +if device.thermalState == .nominal { + print("Thermal state is nominal") +} diff --git a/Example/DeviceKitPlayground.playground/contents.xcplayground b/Example/DeviceKitPlayground.playground/contents.xcplayground index 5da2641..a751024 100644 --- a/Example/DeviceKitPlayground.playground/contents.xcplayground +++ b/Example/DeviceKitPlayground.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Example/DeviceKitPlayground.playground/playground.xcworkspace/contents.xcworkspacedata b/Example/DeviceKitPlayground.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..94b2795 --- /dev/null +++ b/Example/DeviceKitPlayground.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,4 @@ + + + diff --git a/README.md b/README.md index bc30536..136400a 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ `DeviceKit` is a value-type replacement of [`UIDevice`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/). -## Current version 4.8.1 +## Current version 4.9.0 See our detailed [changelog](CHANGELOG.md) for the latest features, improvements and bug fixes. ## Features diff --git a/Source/Device.generated.swift b/Source/Device.generated.swift index 807d0d4..1c1ca67 100644 --- a/Source/Device.generated.swift +++ b/Source/Device.generated.swift @@ -1970,3 +1970,36 @@ extension Device { } #endif + +// MARK: ThermalState +@available(iOS 11.0, watchOS 4.0, macOS 10.10.3, tvOS 11.0, *) +extension Device { + /// The thermal state of the system. + public enum ThermalState { + /// The thermal state is within normal limits. + case nominal + /// The thermal state is slightly elevated. + case fair + /// The thermal state is high. + case serious + /// The thermal state is significantly impacting the performance of the system and the device needs to cool down. + case critical + } + + /// Returns the current thermal state of the system (or nil if not called against the `current` device) + public var thermalState: ThermalState? { + guard isCurrent else { return nil } + switch ProcessInfo().thermalState { + case .nominal: + return .nominal + case .fair: + return .fair + case .serious: + return .serious + case .critical: + return .critical + @unknown default: + return .nominal + } + } +} diff --git a/Source/Device.swift.gyb b/Source/Device.swift.gyb index 0ba8358..965cc6c 100644 --- a/Source/Device.swift.gyb +++ b/Source/Device.swift.gyb @@ -1269,3 +1269,36 @@ extension Device { } #endif + +// MARK: ThermalState +@available(iOS 11.0, watchOS 4.0, macOS 10.10.3, tvOS 11.0, *) +extension Device { + /// The thermal state of the system. + public enum ThermalState { + /// The thermal state is within normal limits. + case nominal + /// The thermal state is slightly elevated. + case fair + /// The thermal state is high. + case serious + /// The thermal state is significantly impacting the performance of the system and the device needs to cool down. + case critical + } + + /// Returns the current thermal state of the system (or nil if not called against the `current` device) + public var thermalState: ThermalState? { + guard isCurrent else { return nil } + switch ProcessInfo().thermalState { + case .nominal: + return .nominal + case .fair: + return .fair + case .serious: + return .serious + case .critical: + return .critical + @unknown default: + return .nominal + } + } +}