{"id":1250,"url":"https://github.com/devicekit/DeviceKit","last_synced_at":"2025-08-06T13:32:20.754Z","repository":{"id":27674019,"uuid":"31160078","full_name":"devicekit/DeviceKit","owner":"devicekit","description":"DeviceKit is a value-type replacement of UIDevice.","archived":false,"fork":false,"pushed_at":"2024-09-26T12:57:42.000Z","size":662,"stargazers_count":4481,"open_issues_count":59,"forks_count":436,"subscribers_count":74,"default_branch":"master","last_synced_at":"2024-12-08T07:43:54.218Z","etag":null,"topics":["battery-level","battery-state","device","device-family","hacktoberfest","ios","simulator","swift","swiftpm","tvos"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devicekit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-22T10:51:16.000Z","updated_at":"2024-12-06T14:21:40.000Z","dependencies_parsed_at":"2023-02-14T04:16:27.070Z","dependency_job_id":"9096a5e7-bea8-4397-b4ef-55c42747f7cc","html_url":"https://github.com/devicekit/DeviceKit","commit_stats":{"total_commits":309,"total_committers":62,"mean_commits":4.983870967741935,"dds":0.7831715210355987,"last_synced_commit":"5757447e9f92c476ee2ca41ead7eb6db07936430"},"previous_names":["dennisweissmann/devicekit"],"tags_count":62,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devicekit%2FDeviceKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devicekit%2FDeviceKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devicekit%2FDeviceKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devicekit%2FDeviceKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devicekit","download_url":"https://codeload.github.com/devicekit/DeviceKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228703529,"owners_count":17959668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["battery-level","battery-state","device","device-family","hacktoberfest","ios","simulator","swift","swiftpm","tvos"],"created_at":"2024-01-05T20:15:42.213Z","updated_at":"2025-08-06T13:32:20.727Z","avatar_url":"https://github.com/devicekit.png","language":"Swift","readme":"\u003cimg src=\"/DeviceKit.svg\" height=\"128\"\u003e\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/devicekit/DeviceKit/master/LICENSE)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/DeviceKit.svg)](https://cocoapods.org/pods/DeviceKit)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![codecov](https://codecov.io/gh/devicekit/DeviceKit/branch/master/graph/badge.svg)](https://codecov.io/gh/devicekit/DeviceKit)\n[![CocoaPods](https://img.shields.io/cocoapods/dt/DeviceKit.svg)](https://cocoapods.org/pods/DeviceKit)\n[![Maintainability](https://api.codeclimate.com/v1/badges/844e23a17bde71ff6be1/maintainability)](https://codeclimate.com/github/devicekit/DeviceKit/maintainability)\n[![Platform](https://img.shields.io/cocoapods/p/DeviceKit.svg?style=flat)](http://cocoadocs.org/docsets/DeviceKit)\n\n\n| Branch | Versions |\n|:---------|:----------:|\n| **master** | ≥ 2.0 |\n| **Swift 4 - 4.2** | ≥ 1.3 \u003c 1.13 |\n| **Swift 3** | ≥ 1.0 \u003c 1.3 |\n| **Swift 2.3** | \u003c 1.0 |\n\n`DeviceKit` is a value-type replacement of [`UIDevice`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/).\n\n## Current version 5.6.0\nSee our detailed [changelog](CHANGELOG.md) for the latest features, improvements and bug fixes.\n\n## Features\n\n- [x] Equatable\n- [x] Device identification\n- [x] Device family detection\n- [x] Device group detection\n- [x] Simulator detection\n- [x] Battery state\n- [x] Battery level\n- [x] Various device metrics (e.g. screen size, screen ratio, PPI)\n- [x] Low Power Mode detection\n- [x] Guided Access Session detection\n- [x] Screen brightness\n- [x] Display Zoom detection\n- [x] Detect available sensors (Touch ID, Face ID)\n- [x] Detect available disk space\n- [x] Apple Pencil support detection\n\n## Requirements\n\n- iOS 11.0+\n- tvOS 11.0+\n- watchOS 4.0+\n\n## Installation\nDeviceKit can be installed in various ways.\n\n### CocoaPods\n\n#### Swift 5\n```ruby\npod 'DeviceKit', '~\u003e 5.2'\n```\n#### iOS 8.0 support\n```ruby\npod 'DeviceKit', '3.2'\n```\n#### Swift 4.0 - Swift 4.2\n```ruby\npod 'DeviceKit', '~\u003e 1.3'\n```\n#### Swift 3\n```ruby\npod 'DeviceKit', '~\u003e 1.2.3'\n```\n#### Swift 2.3 (Unsupported)\n```ruby\npod 'DeviceKit', :git =\u003e 'https://github.com/devicekit/DeviceKit.git', :branch =\u003e 'swift-2.3-unsupported'\n```\n\n### Swift Package Manager\n\n#### Swift 5\n```swift\ndependencies: [\n    .package(url: \"https://github.com/devicekit/DeviceKit.git\", from: \"4.0.0\"),\n    /// ...\n]\n```\n#### iOS 8.0 support\n```swift\ndependencies: [\n    .package(url: \"https://github.com/devicekit/DeviceKit.git\", from: \"3.2.0\"),\n    /// ...\n]\n```\n\n### Carthage\n\n#### Swift 5\n```ogdl\ngithub \"devicekit/DeviceKit\" ~\u003e 4.0\n```\n#### iOS 8.0 support\n```ogdl\ngithub \"devicekit/DeviceKit\" ~\u003e 3.2\n```\n#### Swift 4.0 - Swift 4.2\n```ogdl\ngithub \"devicekit/DeviceKit\" ~\u003e 1.3\n```\n#### Swift 3\n```ogdl\ngithub \"devicekit/DeviceKit\" ~\u003e 1.2.3\n```\n#### Swift 2.3 (Unsupported)\n```ogdl\ngithub \"devicekit/DeviceKit\" \"swift-2.3-unsupported\"\n```\n\n### Manually\nTo install it manually, drag the `DeviceKit` project into your app project in Xcode. Or add it as a git submodule by running:\n```bash\n$ git submodule add https://github.com/devicekit/DeviceKit.git\n```\n\n## Usage\nFirst make sure to import the framework:\n```swift\nimport DeviceKit\n```\n\nHere are some usage examples. All devices are also available as simulators:\n```swift\n.iPhone6 =\u003e .simulator(.iPhone6)\n.iPhone6s =\u003e .simulator(.iPhone6s)\n```\n\nYou can try these examples in Playground.\n\n**Note:**\n\n\u003e To try DeviceKit in the playground, open the `DeviceKit.xcworkspace` and build DeviceKit.framework for any simulator first by selecting \"DeviceKit\" as your current scheme.\n\n### Get the Device You're Running On\n```swift\nlet device = Device.current\n\nprint(device)     // prints, for example, \"iPhone 6 Plus\"\n\nif device == .iPhone6Plus {\n  // Do something\n} else {\n  // Do something else\n}\n```\n\n### Get the Device Family\n```swift\nlet device = Device.current\nif device.isPod {\n  // iPods (real or simulator)\n} else if device.isPhone {\n  // iPhone (real or simulator)\n} else if device.isPad {\n  // iPad (real or simulator)\n}\n```\n\n### Check If Running on Simulator\n```swift\nlet device = Device.current\nif device.isSimulator {\n  // Running on one of the simulators(iPod/iPhone/iPad)\n  // Skip doing something irrelevant for Simulator\n} \n```\n\n### Get the Simulator Device\n```swift\nlet device = Device.current\nswitch device {\ncase .simulator(.iPhone6s): break // You're running on the iPhone 6s simulator\ncase .simulator(.iPadAir2): break // You're running on the iPad Air 2 simulator\ndefault: break\n}\n```\n \n### Make Sure the Device Is Contained in a Preconfigured Group\n```swift\nlet groupOfAllowedDevices: [Device] = [.iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .simulator(.iPhone6), .simulator(.iPhone6Plus),.simulator(.iPhone6s),.simulator(.iPhone6sPlus).simulator(.iPhone8),.simulator(.iPhone8Plus),.simulator(.iPhoneX),.simulator(.iPhoneXS),.simulator(.iPhoneXSMax),.simulator(.iPhoneXR)]\n\nlet device = Device.current\n \nif device.isOneOf(groupOfAllowedDevices) {\n  // Do your action\n}\n```\n\n### Get the Current Battery State\n**Note:**\n\n\u003e To get the current battery state we need to set `UIDevice.current.isBatteryMonitoringEnabled` to `true`. To avoid any issues with your code, we read the current setting and reset it to what it was before when we're done.\n\n```swift\nif device.batteryState == .full || device.batteryState \u003e= .charging(75) {\n  print(\"Your battery is happy! 😊\")\n}\n```\n\n### Get the Current Battery Level\n```swift\nif device.batteryLevel \u003e= 50 {\n  install_iOS()\n} else {\n  showError()\n}\n```\n\n### Get Low Power mode status\n```swift\nif device.batteryState.lowPowerMode {\n  print(\"Low Power mode is enabled! 🔋\")\n} else {\n  print(\"Low Power mode is disabled! 😊\")\n}\n```\n\n### Check if a Guided Access session is currently active\n```swift\nif device.isGuidedAccessSessionActive {\n  print(\"Guided Access session is currently active\")\n} else {\n  print(\"No Guided Access session is currently active\")\n}\n```\n\n### Get Screen Brightness\n```swift\nif device.screenBrightness \u003e 50 {\n  print(\"Take care of your eyes!\")\n}\n```\n\n### Get Available Disk Space\n```swift\nif Device.volumeAvailableCapacityForOpportunisticUsage ?? 0 \u003e Int64(1_000_000) {\n  // download that nice-to-have huge file\n}\n\nif Device.volumeAvailableCapacityForImportantUsage ?? 0 \u003e Int64(1_000) {\n  // download that file you really need\n}\n```\n\n## Source of Information\nAll model identifiers are taken from the following website: https://www.theiphonewiki.com/wiki/Models or extracted from the simulator app bundled with Xcode.\n\n## Contributing\nIf you have the need for a specific feature that you want implemented or if you experienced a bug, please open an issue.\nIf you extended the functionality of DeviceKit yourself and want others to use it too, please submit a pull request.\n\n## Contributors\nThe complete list of people who contributed to this project is available [here](https://github.com/devicekit/DeviceKit/graphs/contributors). DeviceKit wouldn't be what it is without you! Thank you very much! 🙏\n","funding_links":[],"categories":["Hardware","Libs","Swift","HarmonyOS","Device [🔝](#readme)","前端开发框架及项目","Device"],"sub_categories":["Other Hardware","Device","Windows Manager","iOS_Swift应用开发"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevicekit%2FDeviceKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevicekit%2FDeviceKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevicekit%2FDeviceKit/lists"}