All Projects → anatoliyv → Assistantkit

anatoliyv / Assistantkit

Licence: mit
Easy way to detect iOS device properties, OS versions and work with screen sizes. Powered by Swift.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Assistantkit

Responsivedevices.css
Responsive CSS Device frames for your landing pages
Stars: ✭ 59 (-89.63%)
Mutual labels:  iphone, ipad, device
Deviice
Swift library to easily check the current device and some more info about it.
Stars: ✭ 51 (-91.04%)
Mutual labels:  device, iphone, ipad
SwiftyJot
Use your finger to annotate images.
Stars: ✭ 14 (-97.54%)
Mutual labels:  iphone, ipad, swift-framework
Alsystemutilities
THIS REPO IS NO LONGER MAINTAINED! Check https://github.com/andrealufino/Luminous. This library provides a list of 80 methods to get every kind of system information!
Stars: ✭ 644 (+13.18%)
Mutual labels:  iphone, ipad, device
Apple Device Model List
All Apple devices model name list. 通过内部编号判断 iOS 设备型号。
Stars: ✭ 149 (-73.81%)
Mutual labels:  iphone, ipad, device
Mcpicker Ios
McPicker is a customizable, closure driven UIPickerView drop-in solution with animations that is rotation ready.
Stars: ✭ 186 (-67.31%)
Mutual labels:  swift-framework, iphone, ipad
BDLocalizedDevicesModels
Apple devices model names localized.
Stars: ✭ 23 (-95.96%)
Mutual labels:  device, iphone, ipad
Ipa Server
Upload and install IPA in web.
Stars: ✭ 392 (-31.11%)
Mutual labels:  iphone, ipad
Pushok
PHP client for Apple Push Notification Service (APNs) - Send push notifications to iOS using the new APNs HTTP/2 protocol with token-based (JWT with p8 private key)
Stars: ✭ 260 (-54.31%)
Mutual labels:  iphone, ipad
Shortcutsdirectory
A collection of user-submitted shortcuts for Shortcuts for iOS.
Stars: ✭ 376 (-33.92%)
Mutual labels:  iphone, ipad
Showtime
The easiest way to show off your iOS taps and gestures for demos and videos.
Stars: ✭ 281 (-50.62%)
Mutual labels:  iphone, ipad
jyutping
Cantonese Jyutping Keyboard for iOS. 粵語粵拼輸入法鍵盤
Stars: ✭ 23 (-95.96%)
Mutual labels:  iphone, ipad
SpecTools
Write less test code with this set of spec tools. Swift, iOS, testing framework independent (but works well with Quick/Nimble or directly).
Stars: ✭ 38 (-93.32%)
Mutual labels:  iphone, ipad
Readinglist
📚 📱 Reading List - an iOS app to track personal reading lists
Stars: ✭ 266 (-53.25%)
Mutual labels:  iphone, ipad
blobile
Blases Loaded - Unofficial Live Blaseball Game Viewer for iOS, Android, and Web
Stars: ✭ 16 (-97.19%)
Mutual labels:  iphone, ipad
Localradio
📻 LocalRadio is "Radio for Cord-Cutters" – a Software-Defined Radio (SDR) app for your Mac and mobile devices. With an inexpensive RTL-SDR USB device, LocalRadio provides a casual, home-based radio listening experience for your favorite local frequencies - FM broadcasts/free music/news/sports/weather/public safety & aviation scanner/etc.
Stars: ✭ 269 (-52.72%)
Mutual labels:  iphone, ipad
Hackers
Hackers is an elegant iOS app for reading Hacker News written in Swift.
Stars: ✭ 513 (-9.84%)
Mutual labels:  iphone, ipad
Instagram stories
Inspired by Instagram Stories functionality. This source is similar to Instagram Stories, which is having both image and video support.
Stars: ✭ 275 (-51.67%)
Mutual labels:  iphone, ipad
Knphotobrowser
📷 图片 || 视频 浏览器(本地和网络) , UIViewController + CollectionView , 完美适配 iPhone 以及 iPad ,屏幕旋转功能 , 适配SDWebImage 5.0
Stars: ✭ 296 (-47.98%)
Mutual labels:  iphone, ipad
Yampa
Functional Reactive Programming domain-specific language embedded in Haskell, for programming efficient hybrid (mixed discrete-time and continuous-time) systems.
Stars: ✭ 294 (-48.33%)
Mutual labels:  iphone, ipad

AssistantKit

CI Status Version License Platform

Easy way to detect device environment:

Helps to:

Installation

AssistantKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "AssistantKit"

Usage

Device version information

To get the current device type, use:

let device = Device.type

switch device {
case .phone:      print("iPhone")
case .pad:        print("iPad")
case .pod:        print("iPod")
case .simulator:  print("Simulator")
default:          print("Unknown")
}

You can check the exact device version with next code. All possible values of version can be found in the Version enum, located in the Version.swift file.

switch Device.version {
case .phone5C:      print("iPhone 5C")
case .phone6:       print("iPhone 6")
case .phone6S:      print("iPhone 6S")
case .phone6Plus:   print("iPhone 6 Plus")
case .phone6SPlus:  print("iPhone 6 S Plus")
// and more iPhones

case .padAir:       print("iPad Air")
case .padAir2:      print("iPad Air 2")
case .padMini:      print("iPad Mini")
case .padPro:       print("iPad Pro")
// and more iPads

case .podTouch6:    print("iPod 6")
// and more iPods

case .simulator:    print("Simulator")
default:            print("Unknown device")
}

There are few properties that detect device type

Device.isPhone     // true for iPhones even if it's Simulator
Device.isPad       // true for iPads even if it's Simulator
Device.isPadPro    // true for iPad Pros even if it's Simulator
Device.isPod       // true for iPods
Device.isSimulator // true for Simulators
Device.isNotched   // true for newer device version with notch

To get raw device code use

Device.versionCode

Device screen parameters

Detecting screen size can be detected with next code. All possible values could be found in the Screen enum, located in Screen.swift.

switch Device.screen {
case .inches_4_7:  print("4.7 inches")
case .inches_5_5:  print("5.5 inches")
case .inches_7_9:  print("7.9 inches")
case .inches_9_7:  print("9.7 inches")
case .inches_12_9: print("12.9 inches")
default:           print("Other display")
}

Compare screens

Screen is cinfirming to Comparable protocol:

Screen.inches_3_5 < Screen.inches_4_0 // Will be `true`

Detecting screen family

Often it is required to assign different parameters based on specific screen resolution. There are 3 methods that will help you to detect what parameters to use. But first of all let me introduce ScreenFamily.

This is enum that breaks all possible screens into 3 groups:

  • .old: Reproduce old iPhones with 3.5 and 4.0 inches screens
  • .small: Other iPhones/iPods without iPhone 6 Plus
  • .medium: iPhone 6 Plus and iPad Mini
  • .big: iPad and iPad Pro

You can detect screen family by:

let family = Device.screen.family

And now back to methods:

Value by device type

To assign different values for iPhone and iPad devices you can use:

// Method definition
static public func size<T: Any>(phone phone: T, pad: T) -> T

// Usage example
let size = Device.size(phone: 13, pad: 15)
let font = UIFont(name: "Arial", size: CGFloat(size))

On iPhones your font size will be 13.0, on iPads 15.0

Value by ScreenFamily

Another method based on ScreenFamily:

// Method definition
static public func size<T: Any>(small small: T, medium: T, big: T) -> T

// Usage example
let otherSize = Device.size(small: 12, medium: 14, big: 15)
let otherFont = UIFont(name: "Arial", size: CGFloat(otherSize))

In this case for small screens your font will be 12.0, for medium 14.0 and for big 15.0 inches.

Important notice: By default if screen family can not be detected size method will assign small value.

Value by exact screen size

Also you can return value for specific screen size. There is another size method you can use. Incoming parameter should be a screen size. If it is not defined nearest value will be used. Code example:

// Method definition
static public func size<T: Any>(sizes sizes: [Screen : T]) -> T?

// Usage example
let sizes: [Screen: AnyObject] = [
   .inches_3_5: 12,
   .inches_4_0: 13,
   .inches_4_7: 14,
   .inches_9_7: 15
  ]
let exactSize = Device.size(sizes: sizes) as! Int
let _ = UIFont(name: "Arial", size: CGFloat(exactSize))

Important notice: This method can return nil if you pass an empty array as a parameter. Be careful with implicit unwrapping.

After that your font will be:

  • 12 for 3.5" inches (older devices)
  • 13 for iPhone 5, 5S
  • 14 for iPhone 6, 6Plus and iPad mini
  • and 15 for other iPads

Screen scale

switch Device.scale {
case .x1: print("Not retina")
case .x2: print("Retina 2X")
case .x3: print("Retina 3X")
default:  print("Unknown scale")
}

Also there is a property to detect if it's retina display:

Device.isRetina // true if device screen scale > 1.0

Interface orientation

There are two properties that will help you to know current orientation:

Device.isLandscape // true if landscape
Device.isPortrait  // true if portrait

Slide Over / Multitasking layout for iPad

To detect slide over layout on iPads just call:

Device.isSlideOverLayout // true if iPad is in multitasking / slide over layout

Detecting and comparing iOS version

You can detect iOS version in runtime. There are next different methods that will help you to do it:

Device.osVersion                               // Current version as a `OSVersion` model

Device.osVersion == Device.os12                // true if iOS 12.0
Device.osVersion >= Device.os9                 // true if iOS >= 9.0
Device.osVersion < Device.os11                 // true if iOS < 11.0
etc.

There are next constants representating Main iOS versions:

Device.os8
Device.os9
Device.os10
Device.os11
Device.os12

Working with directories

There are few helper methods to make access to Documents and Caches directoies easier. Take a look at code examples:

Bundle.documentsDirectoryURL           // URL to .DocumentDirectory
Bundle.documentsDirectoryPath          // Path to .DocumentDirectory
Bundle.cachesDirectoryURL              // URL to .CachesDirectory
Bundle.cachesDirectoryPath             // Path to .CachesDirectory

let filePath = "directory/filename.txt"
Bundle.filePathInDocumentsDirectory(toFile: filePath)  // Path to file in .DocumentDirectory
Bundle.filePathInCachesDirectory(toFile: filePath)     // Path to file in .CachesDirectory

Environment

Used to detect environment options. Right now there is only one property:

/// Return `true` if running unit tests
Environment.isRunningUnitTests

Battery

There is a way to get battery state and level with these methods. It will enable monitoring if it's not enabled yet.

Device.Battery.state // Represent `UIDeviceBatteryState`
Device.Battery.level // in range 0...1 -1 for simulators

TODO

  • [ ] Add tvOS support

Write me or make a pull request if you have any ideas what else functionality can be useful in this repo.

Author

More Device-detecting libs

License

AssistantKit is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].