Light weight tool for detecting the current device and screen size written in swift.

Overview

Device

Version License Platform Carthage Compatible Twitter

Device detect the current  device model and screen size.

Installation

CocoaPods

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

pod "Device", '~> 3.2.1'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Device into your Xcode project using Carthage, specify it in your Cartfile:

github "Ekhoo/Device" ~> 3.2.1

Run carthage update to build the framework and drag the built Device.framework into your Xcode project.

Usage

iOS

Device version

func myFunc() {
        /*** Display the device version ***/
        switch Device.version() {
            /*** iPhone ***/
            case .iPhone4:       print("It's an iPhone 4")
            case .iPhone4S:      print("It's an iPhone 4S")
            case .iPhone5:       print("It's an iPhone 5")
            case .iPhone5C:      print("It's an iPhone 5C")
            case .iPhone5S:      print("It's an iPhone 5S")
            case .iPhone6:       print("It's an iPhone 6")
            case .iPhone6S:      print("It's an iPhone 6S")
            case .iPhone6Plus:   print("It's an iPhone 6 Plus")
            case .iPhone6SPlus:  print("It's an iPhone 6 S Plus")
            case .iPhoneSE:      print("It's an iPhone SE")
            case .iPhone7:       print("It's an iPhone 7")
            case .iPhone7Plus:   print("It's an iPhone 7 Plus")
            case .iPhone8:       print("It's an iPhone 8")
            case .iPhone8Plus:   print("It's an iPhone 8 Plus")
            case .iPhoneX:       print("It's an iPhone X")
            case .iPhoneXS:      print("It's an iPhone Xs")
            case .iPhoneXS_Max:  print("It's an iPhone Xs Max")
            case .iPhoneXR:      print("It's an iPhone Xr")

            /*** iPad ***/
            case .iPad1:           print("It's an iPad 1")
            case .iPad2:           print("It's an iPad 2")
            case .iPad3:           print("It's an iPad 3")
            case .iPad4:           print("It's an iPad 4")
            case .iPad5:           print("It's an iPad 5")
            case .iPad6:           print("It's an iPad 6")
            case .iPadAir:         print("It's an iPad Air")
            case .iPadAir2:        print("It's an iPad Air 2")
            case .iPadMini:        print("It's an iPad Mini")
            case .iPadMini2:       print("It's an iPad Mini 2")
            case .iPadMini3:       print("It's an iPad Mini 3")
            case .iPadMini4:       print("It's an iPad Mini 4")
            case .iPadPro9_7Inch:  print("It's an iPad Pro 9.7 Inch")
            case .iPadPro10_5Inch: print("It's an iPad Pro 10.5 Inch")
            case .iPadPro12_9Inch: print("It's an iPad Pro 12.9 Inch")

            /*** iPod ***/
            case .iPodTouch1Gen: print("It's a iPod touch generation 1")
            case .iPodTouch2Gen: print("It's a iPod touch generation 2")
            case .iPodTouch3Gen: print("It's a iPod touch generation 3")
            case .iPodTouch4Gen: print("It's a iPod touch generation 4")
            case .iPodTouch5Gen: print("It's a iPod touch generation 5")
            case .iPodTouch6Gen: print("It's a iPod touch generation 6")

            /*** Simulator ***/
            case .Simulator:    print("It's a Simulator")

            /*** Unknown ***/
            default:            print("It's an unknown device")
        }
    }

Device screen size

func myFunc() {
        /*** Display the device screen size ***/
        switch Device.size() {
            case .screen3_5Inch:  print("It's a 3.5 inch screen")
            case .screen4Inch:    print("It's a 4 inch screen")
            case .screen4_7Inch:  print("It's a 4.7 inch screen")
            case .screen5_5Inch:  print("It's a 5.5 inch screen")
            case .screen5_8Inch:  print("It's a 5.8 inch screen")
            case .screen6_1Inch:  print("It's a 6.1 inch screen")
            case .screen6_5Inch:  print("It's a 6.8 inch screen")
            case .screen7_9Inch:  print("It's a 7.9 inch screen")
            case .screen9_7Inch:  print("It's a 9.7 inch screen")
            case .screen10_5Inch: print("It's a 10.5 inch screen")
            case .screen12_9Inch: print("It's a 12.9 inch screen")
            default:              print("Unknown size")
        }
}

Device type

func myFunc() {
        /*** Display the device type ***/
        switch Device.type() {
            case .iPod:         print("It's an iPod")
            case .iPhone:       print("It's an iPhone")
            case .iPad:         print("It's an iPad")
            case .Simulator:    print("It's a Simulated device")
            default:            print("Unknown device type")
        }
}

or

func myFunc() {
        /*** Display the device type ***/
        if (Device.isPad()){
            print("It's an iPad")
        }
        else if (Device.isPhone()){
            print("It's an iPhone")
        }
        else if (Device.isPod()){
            print("It's an iPod")
        }
        else if (Device.isSimulator()){
            print("It's a Simulated device")
        }
}

Mac

Mac version

func myFunc() {
        /*** Display the mac version ***/
        switch Device.type() {
            case .iMac:         print("It's an iMac")
            case .macBook:      print("It's a MacBook")
            case .macBookAir:   print("It's a MacBook Air")
            case .macBookPro:   print("It's a MacBook Pro")
            default:            print("Unknown device type")
        }
    }

Mac screen size

func myFunc() {
        /*** Display the mac screen size ***/
        switch Device.size() {
            case .screen11Inch:     print("It's a 11 inch screen")
            case .screen12Inch:     print("It's a 12 inch screen")
            case .screen13Inch:     print("It's a 13 inch screen")
            case .screen15Inch:     print("It's a 15 inch screen")
            case .screen17Inch:     print("It's a 17 inch screen")
            case .screen21_5Inch:   print("It's a 21.5 inch screen")
            case .screen27Inch:     print("It's a 27 inch screen")
            default:                print("Unknown size")
        }
}

Helpers

func myFunc() {
        /*** Helpers ***/
        if Device.size() == Size.screen4Inch {
            print("It's a 4 inch screen")
        }

        if Device.size() > Size.screen4_7Inch {
            print("Your device screen is larger than 4.7 inch")
        }

        if Device.size() < Size.screen4_7Inch {
            print("Your device screen is smaller than 4.7 inch")
        }

        if Device.size() == Size.screen27Inch {
            print("It's a 27 inch screen")
        }
        
        if Device.size() > Size.screen15Inch {
            print("Your mac screen is larger than 15 inch")
        }
        
        if Device.size() < Size.screen15Inch {
            print("Your mac screen is smaller than 15 inch")
        }

        if Device.isRetina() {
            print("It's a retina display")
        }
        
}

Author

Lucas Ortis:

License

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

Comments
  • Is this project still maintained?

    Is this project still maintained?

    Hi!

    Given the number of issues open and the absence of support for the last iOS devices (iPhone 13), I wanted to ask if this project is still being maintained?

    opened by fmessina 16
  • Adding support for iPhone 12 devices and previously missing ones

    Adding support for iPhone 12 devices and previously missing ones

    Thanks to @felixbuenemann, this PR covers his changes as well as new types of iPhone 12 devices that have been recently introduced.

    Thus, it fixes the following issues: https://github.com/Ekhoo/Device/pull/90, https://github.com/Ekhoo/Device/issues/94, https://github.com/Ekhoo/Device/issues/101, https://github.com/Ekhoo/Device/issues/105.

    opened by ozgur 10
  • macOS support

    macOS support

    Close #25 Device for macOS is exactly the same as iOS, I just removed the helpers methods (maybe others dedicated to mac will come later), and I changed a bit version. Since almost each mac can have 2-3 different screen size, it's annoying to test them one by one.

    Also, I didn't update the README, I prefer to let you do it since it can be a big change. Otherwise, everything is up to date (including the podspec) :)

    opened by tbaranes 9
  • Suggestion for more helper functions

    Suggestion for more helper functions

    Hey,

    I think it would be really useful (for me at least) if we could have some extra helper functions that simply return either true or false. A function that returns true if the current device is either a 4inch or below etc.

    Of course I can just write them myself in my project, but thought it might be useful if they were part of this lib. What do you think?

    opened by jyounus 8
  • iPhone Xs, Xs Max, Xʀ + iPad (6th gen.) + Swift 4

    iPhone Xs, Xs Max, Xʀ + iPad (6th gen.) + Swift 4

    @Ekhoo Started here: https://github.com/Sweefties/Device/commit/7e7f025d6895b0acb9f2c36f881dd307b71ebfdf & https://github.com/Sweefties/Device/commit/c6da20eaa00405ca1f3067e0e6a4966fac127fd5

    wait for checks (models identifiers)..

    opened by Sweefties 6
  • Support iPhone 12 Screen Sizes

    Support iPhone 12 Screen Sizes

    iPhone 12 Mini: 5.4" with 1080×2340 pixels iPhone 12 / 12 Pro: 6.1" with 1170×2532 pixels iPhone 12 Pro Max: 6.7" with 1284×2778 pixels

    opened by jonahollman 5
  • 1.1.0 is not compatible with 1.0.3

    1.1.0 is not compatible with 1.0.3

    Carthage's operator ~> means the version equals or later than right-hand version which is compatible with that And also, this rule from the semantic versioning. http://semver.org/

    If you can follow this rule, It's better to version as 2.0.0 because 1.1.0 is just supporting Swift3 and Swift3 is not compatible with Swift2.3 (1.0.3 or earlier).

    In other word, if we wrote github "Ekhoo/Device" ~> 1.0.3, we can't build the library without changes of our codes.

    opened by RyogaK 4
  • Properties, lazy computation and system version

    Properties, lazy computation and system version

    Hey, thanks for the lib!

    This PR introduces some breaking changes and I would love to discuss them.

    • versionCode and screenHeight are lazily evaluated
    • device, type and size are now properties
    • Size conforms to the Comparable protocol
    • Add Device.systemVersion

    The updated version of the README is here

    Feedback welcomed :smiley:

    opened by delba 4
  • Add shorcut isPad, isPhone, isPod

    Add shorcut isPad, isPhone, isPod

    First of all, thanks for this pod.

    A lot of times I want to check if the current device is of a specific type and I think it would be easier doing

     if(Device.isPad()) //instead of  if (Device.type() == .iPad) 
    

    So what do you think if I create a PR with the following code?

        static public func isPad() -> Bool {
            return Device.type() == .iPad
        }
    
        static public func isPhone() -> Bool {
            return Device.type() == .iPhone
    
        }
    
        static public func isPod() -> Bool {
            return Device.type() == .iPod
        }
    
    opened by PGLongo 3
  • Fall back device size

    Fall back device size

    Apple releases new devices each year(sometimes some season), and it force this library to release new version whenever new size of device came out.

    When it comes to device size, most of people expect this lib to do its best effort, I think.

    So I'd like to propose Device.size to return the nearest size as long as they know in the released version.

    Once my proposal accepted, Device.size would be implemented like below.

        static public func size() -> Size {
            / * bra bra bra * /
            switch screenHeight {
                case 0...480:
                    return .screen3_5Inch
                case 481...568:
                    return .screen4Inch
                case 569...667:
                    return UIScreen.main.scale == 3.0 ? .screen5_5Inch : .screen4_7Inch
                case 668...736:
                    return .screen5_5Inch
               /* and so on... */
    

    What do you people think about this?

    opened by mickamy 0
  • VIDEO TUTORIAL ON YOUTUBE

    VIDEO TUTORIAL ON YOUTUBE

    Hi,

    I love your repo so much that I have created a YouTube video tutorial on it:

    https://www.youtube.com/watch?v=cTZcOaGgD-E

    Feel free to add it to the README with the following image (people click on images more often than simple links)

    detect current device type in swift easy thubmnail

    Keep up the good work :)

    opened by rebeloper 0
  • improve getType funcs

    improve getType funcs

    Improve getType(_:) -> Type funcs by adding code for using input parameter instead of getting a new one (at the getType func) and leaving input unused

    opened by hellensoloviy 1
Releases(3.3.0)
Owner
Lucas Ortis
iOS developer @Privowny
Lucas Ortis
Thingy - A modern device detection and querying library.

Thingy A modern device detection and querying library. Features Swift 5 support Modern syntax Documentation Device detection Device family detection D

Bojan Dimovski 58 Oct 5, 2022
Super-lightweight library to detect used device

Device.swift Super-lightweight library to detect used device Device.swift extends the UIDevice class by adding a property: var deviceType: DeviceType

Johannes Schickling 219 Nov 17, 2022
Launch JIT enabled iOS app with a second iOS device

Jitterbug This app uses libimobiledevice and WiFi pairing to use one iOS device to launch apps with the debugger on another iOS device. This "tethered

null 645 Jan 6, 2023
Inspect the iOS 15 App Activity Data directly on device.

AppActivityViewer About AppActivityViewer helps to inspect the iOS 15 App Activity Data easily on device. Choose App Activity at share sheet after cli

CJ 15 Mar 30, 2022
Luminous provides you a lot of information about the system and a lot of handy methods to quickly get useful data on the iOS platform.

Luminous Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 8+ Swift 5 Xcode 1

Andrea Mario Lufino 324 Nov 27, 2022
Light weight tool for detecting the current device and screen size written in swift.

Device detect the current  device model and screen size. Installation CocoaPods Device is available through CocoaPods. To install it, simply add the

Lucas Ortis 1.5k Dec 28, 2022
Lightweight Cocoa library for detecting the running device's model and screen size.

Lightweight Cocoa library for detecting the running device's model and screen size. With the newer  devices, developers have more work to do. This li

Sebastian Dobrincu 1.3k Nov 24, 2022
Light weight charts view generater for iOS. Written in Swift.

# ###Light weight charts view generater for iOS. Written in Swift. Requirements iOS 8.0+ XCode 7.3+ Installation CocoaPods $ pod init specify it in yo

Recruit Holdings. Media Technology Lab 982 Nov 16, 2022
A light-weight server-side service framework written in the Swift programming language.

Smoke Framework The Smoke Framework is a light-weight server-side service framework written in Swift and using SwiftNIO for its networking layer by de

Amazon 1.4k Dec 22, 2022
TTProgressHUD is a light weight HUD written in SwiftUI meant to display the progress of an ongoing task on iOS.

TTProgressHUD TTProgressHUD is a light weight HUD written in SwiftUI meant to display the progress of an ongoing task on iOS. TTProgressHUD (left) was

Tobias Totzek 184 Dec 27, 2022
A realistic reflective shimmer to SwiftUI Views that uses device orientation. Position any View relative to device orientation to appear as if through a window or reflected by the screen.

A 3d rotation effect that uses Core Motion to allow SwiftUI views to appear projected in a specific direction and distance relative to the device in r

Ryan Lintott 235 Dec 30, 2022
IOS-Application-3 - A basic calculator app for iOS compatible to any layout and screen size

Calculator It is a basic calculator app for iOS compatible to any layout and scr

Kushal Shingote 1 Feb 2, 2022
FlightLayout is a light weight, and easy to learn layout framework as an extension of the UIView.

FlightLayout Introduction FlightLayout is a light weight, and easy to learn layout framework as an extension of the UIView. Functionally, it lives som

Anton 23 Apr 21, 2022
Switchboard - easy and super light weight A/B testing for your mobile iPhone or android app. This mobile A/B testing framework allows you with minimal servers to run large amounts of mobile users.

Switchboard - easy A/B testing for your mobile app What it does Switchboard is a simple way to remote control your mobile application even after you'v

Keepsafe 287 Nov 19, 2022
Simple and light weight slider with chapter management

Simple and light weight slider with chapter management Demo Installation CocoaPods WESlider is available through CocoaPods. To install it, simply add

Lucas Ortis 89 Nov 29, 2022
A light-weight UITextView subclass that automatically grows and shrinks.

RSKGrowingTextView A light-weight UITextView subclass that automatically grows and shrinks based on the size of user input and can be constrained by m

Ruslan Skorb 939 Dec 21, 2022
Simple and light weight facebook login library for UIKit & SwiftUI

MjFbLogin Simple and light weight facebook login library which provides support for UIKit & SwiftUI Example To run the example project, clone the repo

Mohammad Jeeshan 2 Jul 3, 2022
A light weight & simple & easy camera for iOS by Swift.

DKCamera Description A light weight & simple & easy camera for iOS by Swift. It uses CoreMotion framework to detect device orientation, so the screen-

Bannings 86 Aug 18, 2022
An unintrusive & light-weight iOS app-theming library with support for animated theme switching.

Gestalt Gestalt is an unintrusive and light-weight framework for application theming with support for animated theme switching. Usage Let's say you wa

Vincent Esche 327 Nov 8, 2022
Light-weight, operator-overloading-free complements to CoreGraphics!

Graphicz ?? Light-weight, operator-overloading-free complements to CoreGraphics! Even though I shipped it with my app, I still need to invest the time

Kitz 44 Oct 25, 2021