{"id":3023,"url":"https://github.com/anatoliyv/AssistantKit","last_synced_at":"2025-08-03T12:32:04.415Z","repository":{"id":55904400,"uuid":"60693338","full_name":"anatoliyv/AssistantKit","owner":"anatoliyv","description":"Easy way to detect iOS device properties, OS versions and work with screen sizes. Powered by Swift.","archived":false,"fork":false,"pushed_at":"2020-12-08T08:42:30.000Z","size":180,"stargazers_count":588,"open_issues_count":5,"forks_count":52,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-12-05T18:47:32.818Z","etag":null,"topics":["battery","device","ios","ios-device","ios-framework","ipad","iphone","swift","swift-4","swift-framework"],"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/anatoliyv.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}},"created_at":"2016-06-08T11:37:30.000Z","updated_at":"2024-11-21T08:24:38.000Z","dependencies_parsed_at":"2022-08-15T09:10:10.044Z","dependency_job_id":null,"html_url":"https://github.com/anatoliyv/AssistantKit","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anatoliyv%2FAssistantKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anatoliyv%2FAssistantKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anatoliyv%2FAssistantKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anatoliyv%2FAssistantKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anatoliyv","download_url":"https://codeload.github.com/anatoliyv/AssistantKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228543279,"owners_count":17934455,"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","device","ios","ios-device","ios-framework","ipad","iphone","swift","swift-4","swift-framework"],"created_at":"2024-01-05T20:16:29.227Z","updated_at":"2024-12-07T00:31:14.181Z","avatar_url":"https://github.com/anatoliyv.png","language":"Swift","readme":"![AssistantKit](https://cloud.githubusercontent.com/assets/1595032/15893439/631458ec-2d88-11e6-8566-4023999df805.png)\n\n[![CI Status](http://img.shields.io/travis/anatoliyv/AssistantKit.svg?style=flat)](https://travis-ci.org/anatoliyv/AssistantKit)\n[![Version](https://img.shields.io/cocoapods/v/AssistantKit.svg?style=flat)](http://cocoapods.org/pods/AssistantKit)\n[![License](https://img.shields.io/cocoapods/l/AssistantKit.svg?style=flat)](http://cocoapods.org/pods/AssistantKit)\n[![Platform](https://img.shields.io/cocoapods/p/AssistantKit.svg?style=flat)](http://cocoapods.org/pods/AssistantKit)\n![](https://img.shields.io/badge/Supported-iOS8..iOS12-4BC51D.svg?style=flat)\n![](https://img.shields.io/badge/Swift4.2-compatible-4BC51D.svg?style=flat)\n\n\nEasy way to detect device environment:\n- [x] [Device model and version](https://github.com/anatoliyv/AssistantKit#device-version-information)\n- [x] [Screen resolution](https://github.com/anatoliyv/AssistantKit#device-screen-parameters)\n- [x] [Interface orientation](https://github.com/anatoliyv/AssistantKit#interface-orientation)\n- [x] [iOS version](https://github.com/anatoliyv/AssistantKit#detecting-and-comparing-ios-version)\n- [x] [Battery state](https://github.com/anatoliyv/AssistantKit#battery)\n- [x] [Environment](https://github.com/anatoliyv/AssistantKit#environment)\n\n\nHelps to:\n- [x] [work with bundle Document and Cache folders](https://github.com/anatoliyv/AssistantKit/blob/master/README.md#working-with-directories)\n- [x] [easily assign sizes for different devices](https://github.com/anatoliyv/AssistantKit#detecting-screen-family)\n\n## Installation\n\nAssistantKit is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"AssistantKit\"\n```\n\n## Usage\n\n### Device version information\n\nTo get the current device type, use:\n\n```swift\nlet device = Device.type\n\nswitch device {\ncase .phone:      print(\"iPhone\")\ncase .pad:        print(\"iPad\")\ncase .pod:        print(\"iPod\")\ncase .simulator:  print(\"Simulator\")\ndefault:          print(\"Unknown\")\n}\n```\n\nYou can check the exact device version with next code. All possible values of `version` can be\nfound in the `Version` enum, located in the `Version.swift` file.\n\n```swift\nswitch Device.version {\ncase .phone5C:      print(\"iPhone 5C\")\ncase .phone6:       print(\"iPhone 6\")\ncase .phone6S:      print(\"iPhone 6S\")\ncase .phone6Plus:   print(\"iPhone 6 Plus\")\ncase .phone6SPlus:  print(\"iPhone 6 S Plus\")\n// and more iPhones\n\ncase .padAir:       print(\"iPad Air\")\ncase .padAir2:      print(\"iPad Air 2\")\ncase .padMini:      print(\"iPad Mini\")\ncase .padPro:       print(\"iPad Pro\")\n// and more iPads\n\ncase .podTouch6:    print(\"iPod 6\")\n// and more iPods\n\ncase .simulator:    print(\"Simulator\")\ndefault:            print(\"Unknown device\")\n}\n```\n\nThere are few properties that detect device type\n\n```swift\nDevice.isPhone     // true for iPhones even if it's Simulator\nDevice.isPad       // true for iPads even if it's Simulator\nDevice.isPadPro    // true for iPad Pros even if it's Simulator\nDevice.isPod       // true for iPods\nDevice.isSimulator // true for Simulators\nDevice.isNotched   // true for newer device version with notch\n```\n\nTo get raw device code use\n\n```\nDevice.versionCode\n```\n\n### Device screen parameters\n\nDetecting screen size can be detected with next code. All possible values could be\nfound in the `Screen` enum, located in `Screen.swift`.\n\n```swift\nswitch Device.screen {\ncase .inches_4_7:  print(\"4.7 inches\")\ncase .inches_5_5:  print(\"5.5 inches\")\ncase .inches_7_9:  print(\"7.9 inches\")\ncase .inches_9_7:  print(\"9.7 inches\")\ncase .inches_12_9: print(\"12.9 inches\")\ndefault:           print(\"Other display\")\n}\n```\n\n### Compare screens\n\n`Screen` is cinfirming to `Comparable` protocol:\n\n```\nScreen.inches_3_5 \u003c Screen.inches_4_0 // Will be `true`\n```\n\n### Detecting screen family\n\nOften it is required to assign different parameters based on specific screen resolution.\nThere are 3 methods that will help you to detect what parameters to use. But\nfirst of all let me introduce `ScreenFamily`.\n\nThis is enum that breaks all possible screens into 3 groups:\n- `.old`:          Reproduce old iPhones with 3.5 and 4.0 inches screens\n- `.small`:        Other iPhones/iPods without iPhone 6 Plus\n- `.medium`:       iPhone 6 Plus and iPad Mini\n- `.big`:          iPad and iPad Pro\n\nYou can detect screen family by:\n\n```swift\nlet family = Device.screen.family\n```\n\nAnd now back to methods:\n\n#### Value by device type\n\nTo assign different values for iPhone and iPad devices you can use:\n\n```swift\n// Method definition\nstatic public func size\u003cT: Any\u003e(phone phone: T, pad: T) -\u003e T\n\n// Usage example\nlet size = Device.size(phone: 13, pad: 15)\nlet font = UIFont(name: \"Arial\", size: CGFloat(size))\n```\n\nOn iPhones your font size will be 13.0, on iPads 15.0\n\n#### Value by ScreenFamily\n\nAnother method based on `ScreenFamily`:\n\n```swift\n// Method definition\nstatic public func size\u003cT: Any\u003e(small small: T, medium: T, big: T) -\u003e T\n\n// Usage example\nlet otherSize = Device.size(small: 12, medium: 14, big: 15)\nlet otherFont = UIFont(name: \"Arial\", size: CGFloat(otherSize))\n```\n\nIn this case for small screens your font will be 12.0, for medium 14.0 and for big 15.0 inches.\n\n*Important notice:* By default if screen family can not be detected `size` method will\nassign small value.\n\n#### Value by exact screen size\n\nAlso you can return value for specific screen size. There is another size method you can use.\nIncoming parameter should be a screen size. If it is not defined nearest value will be used. Code example:\n\n```swift\n// Method definition\nstatic public func size\u003cT: Any\u003e(sizes sizes: [Screen : T]) -\u003e T?\n\n// Usage example\nlet sizes: [Screen: AnyObject] = [\n   .inches_3_5: 12,\n   .inches_4_0: 13,\n   .inches_4_7: 14,\n   .inches_9_7: 15\n  ]\nlet exactSize = Device.size(sizes: sizes) as! Int\nlet _ = UIFont(name: \"Arial\", size: CGFloat(exactSize))\n```\n\n*Important notice:* This method can return `nil` if you pass an empty array as a parameter. Be careful with implicit unwrapping.\n\nAfter that your font will be:\n- 12 for 3.5\" inches (older devices)\n- 13 for iPhone 5, 5S\n- 14 for iPhone 6, 6Plus and iPad mini\n- and 15 for other iPads\n\n### Screen scale\n\n```swift\nswitch Device.scale {\ncase .x1: print(\"Not retina\")\ncase .x2: print(\"Retina 2X\")\ncase .x3: print(\"Retina 3X\")\ndefault:  print(\"Unknown scale\")\n}\n```\n\nAlso there is a property to detect if it's retina display:\n\n```swift\nDevice.isRetina // true if device screen scale \u003e 1.0\n```\n\n### Interface orientation\n\nThere are two properties that will help you to know current orientation:\n\n```swift\nDevice.isLandscape // true if landscape\nDevice.isPortrait  // true if portrait\n```\n\n### Slide Over / Multitasking layout for iPad\n\nTo detect slide over layout on iPads just call:\n\n```swift\nDevice.isSlideOverLayout // true if iPad is in multitasking / slide over layout\n```\n\n## Detecting and comparing iOS version\n\nYou can detect iOS version in runtime. There are next different methods that will help you to\ndo it:\n\n ```swift\n Device.osVersion                               // Current version as a `OSVersion` model\n\n Device.osVersion == Device.os12                // true if iOS 12.0\n Device.osVersion \u003e= Device.os9                 // true if iOS \u003e= 9.0\n Device.osVersion \u003c Device.os11                 // true if iOS \u003c 11.0\n etc.\n ```\n\nThere are next constants representating Main iOS versions:\n\n ```swift\n Device.os8\n Device.os9\n Device.os10\n Device.os11\n Device.os12\n ```\n\n### Working with directories\n\nThere are few helper methods to make access to Documents and Caches directoies easier.\nTake a look at code examples:\n\n```swift\nBundle.documentsDirectoryURL           // URL to .DocumentDirectory\nBundle.documentsDirectoryPath          // Path to .DocumentDirectory\nBundle.cachesDirectoryURL              // URL to .CachesDirectory\nBundle.cachesDirectoryPath             // Path to .CachesDirectory\n\nlet filePath = \"directory/filename.txt\"\nBundle.filePathInDocumentsDirectory(toFile: filePath)  // Path to file in .DocumentDirectory\nBundle.filePathInCachesDirectory(toFile: filePath)     // Path to file in .CachesDirectory\n```\n\n## Environment\n\nUsed to detect environment options. Right now there is only one property:\n\n```\n/// Return `true` if running unit tests\nEnvironment.isRunningUnitTests\n```\n\n## Battery\n\nThere is a way to get battery state and level with these methods. It will enable monitoring if it's not enabled yet.\n\n```\nDevice.Battery.state // Represent `UIDeviceBatteryState`\nDevice.Battery.level // in range 0...1 -1 for simulators\n```\n\n## TODO\n\n- [ ] Add tvOS support\n\nWrite me or make a pull request if you have any ideas what else functionality can be useful in this repo.\n\n## Author\n\n- anatoliy.voropay@gmail.com\n- [@anatoliy_v](https://twitter.com/anatoliy_v)\n- [LinkedIn](https://www.linkedin.com/in/anatoliyvoropay)\n\n## More Device-detecting libs\n- [Ehkoo's Device](https://github.com/Ekhoo/Device)\n- [Schickling's Device.swift](https://github.com/schickling/Device.swift)\n- [DeviceKit](https://github.com/dennisweissmann/DeviceKit)\n\n## License\n\nAssistantKit is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":["Utility","Swift"],"sub_categories":["Web View","Other free courses"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanatoliyv%2FAssistantKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanatoliyv%2FAssistantKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanatoliyv%2FAssistantKit/lists"}