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
Swift library to easily check the current device and some more info about it.

Usage To run the example project, clone the repo, and run pod install from the Example directory first. let device = Deviice.current device is a Devi

Andrea Mario Lufino 56 Nov 3, 2022
This is an POC for showing current Air Quality of different Cities in graphical format using webSocket

Air-Quality-Monitoring This is an POC for showing current Air Quality of different Cities in graphical format using webSocket. It Used danielgindi/Cha

null 1 Jun 14, 2022
TapticEngine generates haptic feedback vibrations on iOS device.

TapticEngine Overview TapticEngine generates haptic feedback vibrations on iOS device. This library wrapps on UIImpactFeedbackGenerator, UISelectionFe

WorldDownTown 253 Oct 28, 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
Grab kbsync dynamically from your jailbroken iOS device.

KbsyncTool Grab kbsync dynamically from your jailbroken iOS device. Usage Test1:~ root# kbsynctool -s 9000 [DEBUG] Did open IPv4 listening socket 3 [D

i_82 13 Oct 31, 2022
WatchCon is a tool which enables creating easy connectivity between iOS and WatchOS.

WatchCon WatchCon is a tool which enables creating easy connectivity between iOS and WatchOS Requirements iOS 9.0+ / watchOS 2.0+ CocoaPods CocoaPods

Abdullah Selek 33 Sep 22, 2022
A better way to operate QR Code in Swift, support iOS, macOS, watchOS and tvOS.

EFQRCode is a lightweight, pure-Swift library for generating stylized QRCode images with watermark or icon, and for recognizing QRCode from images, in

EFPrefix 4.3k Jan 2, 2023
Instagram-like photo browser and a camera feature with a few line of code in Swift.

NOTE: This project is no longer maintained. We highly recommend YPImagePicker. Fusuma Fusuma is a Swift library that provides an Instagram-like photo

Yuta Akizuki 2.4k Dec 31, 2022
🛰 CoreLocation Made Easy - Efficient & Easy Location Tracker, IP Location, Gecoder, Geofence, Autocomplete, Beacon Ranging, Broadcaster and Visits Monitoring

Location Manager Made Easy SwiftLocation is a lightweight Swift Library that provides an easy way to work with location-related functionalities. No mo

Daniele Margutti 3.2k Dec 30, 2022
A camera view controller with custom image picker and image cropping.

ALCameraViewController A camera view controller with custom image picker and image cropping. Features Front facing and rear facing camera Simple and c

Alex Littlejohn 2k Dec 29, 2022
:mag_right: A simple and beautiful barcode scanner.

Description BarcodeScanner is a simple and beautiful wrapper around the camera with barcode capturing functionality and a great user experience. Barco

HyperRedink 1.6k Jan 3, 2023
Library for iOS Camera API. Massively increase performance and ease of use within your next iOS Project.

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service that scales,

CameraKit 628 Dec 27, 2022
Get the data from Accelerometer, Gyroscope and Magnetometer in only Two or a few lines of code.

Get the data from Accelerometer, Gyroscope and Magnetometer in only Two or a few lines of code. CoreMotion now made insanely simple :octocat: :satellite:

Muhammad Haroon Baig 1.1k Nov 16, 2022
Simply the fastest way to transmit data between iOS/tvOS and OSX

DarkLightning DarkLightning is a lightweight Swift library to allow data transmission between iOS/tvOS devices (Lightning port, Dock connector, USB-C)

Jens Meder 318 Nov 29, 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
NFC Forum Well Known Type Data Parser for iOS11 and Core NFC

NFCNDEFParse NFC Forum Well Known Type Data Parser for iOS11 and Core NFC. Supports parsing of types: Text - NFCForum-TS-RTD_Text_1.0 2006-07-24 Uri -

Jari Kalinainen 14 Oct 21, 2022
Writes twitter and contact (links) to writable nfcs on iPhone 7+ iOS 14+

nfc writer ios app nfc writer app is a hacky fun side project that writes twitter and contact (links) to writable nfcs. runs on iPhone 7+ iOS 14+. joi

Vivian Phung 5 Nov 23, 2022
⬆️ Rad Media Capture in Swift

NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS. Integration can optionally lev

NextLevel 2k Dec 30, 2022
Simple QRCode reader in Swift

QRCodeReader.swift is a simple code reader (initially only QRCode) for iOS in Swift. It is based on the AVFoundation framework from Apple in order to

Yannick Loriot 1.3k Jan 5, 2023