Lightweight Cocoa library for detecting the running device's model and screen size.

Related tags

Hardware SDVersion
Overview

SDVersion

Gitter Platform Cocoapods Version

Lightweight Cocoa library for detecting the running device's model and screen size.

With the newer  devices, developers have more work to do. This library simplifies their job by allowing them to get information about the running device and easily target the ones they want.

SDVersion supports iOS, watchOS, tvOS, and macOS. Browse through the implementation of each platform using the links below.

iOS Mac

How it works

      // Check for device model
      if ([SDVersion deviceVersion] == iPhone7)
           NSLog(@"You got the iPhone 7. Sweet 🍭!");
      else if ([SDVersion deviceVersion] == iPhone6SPlus)
           NSLog(@"iPhone 6S Plus? Bigger is better!");
      else if ([SDVersion deviceVersion] == iPadAir2)
      	   NSLog(@"You own an iPad Air 2 🌀!");

      // Check for device screen size
      if ([SDVersion deviceSize] == Screen4Dot7inch)
           NSLog(@"Your screen is 4.7 inches");

      // Check if screen is in zoom mode
      if ([SDVersion isZoomed])
      	   NSLog(@"Your device is in Zoom Mode 🔎");

      // Get device name
      NSLog(@"%@", [SDVersion deviceNameString]);
      /* e.g: Outputs 'iPhone 7 Plus' */

      // Check for iOS Version
      if ([SDVersion versionGreaterThanOrEqualTo:@"10"])
           NSLog(@"You are running iOS 10 or above!");

SDVersion Swift
Swift Version:

      // Check for device model
      if SDiOSVersion.deviceVersion() == .iPhone7 {
            print("You got the iPhone 7. Sweet 🍭!")
      }

      // Check for device screen size
      if SDiOSVersion.deviceSize() == .Screen3Dot5inch {
            print("Still on 3.5 inches!? 😮")
      }

      // Get device name
      print(SDiOSVersion.deviceNameString())
      /* e.g: Outputs 'iPhone 7 Plus' */

      // Check for iOS Version
      if SDiOSVersion.versionGreaterThan("10") {
            print("You are running iOS 10 or above!")
      }

Add to your project

There are 2 ways you can add SDVersion to your project:

Manual installation

Simply import the 'SDVersion' into your project then import the following in the class you want to use it:

      #import "SDVersion.h"

In Swift, you need to import in the bridging header the specific library version, not the library wrapper:

     #import "SDiOSVersion.h" // Or SDMacVersion.h

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like SDVersion in your projects. See the "Getting Started" guide for more information.

Podfile

        pod 'SDVersion'

iOS

Available methods

	+ (DeviceVersion)deviceVersion;
	+ (NSString *)deviceNameForVersion:(DeviceVersion)deviceVersion;
	+ (DeviceSize)resolutionSize;
	+ (DeviceSize)deviceSize;
	+ (NSString *)deviceSizeName:(DeviceSize)deviceSize;
	+ (NSString *)deviceNameString;
	+ (BOOL)isZoomed;

Targetable models

iPhone4
iPhone4S
iPhone5
iPhone5C
iPhone5S
iPhone6
iPhone6Plus
iPhone6S
iPhone6SPlus
iPhoneSE
iPhone7
iPhone7Plus

iPad1
iPad2
iPadMini
iPad3
iPad4
iPadAir
iPadMini2
iPadAir2
iPadMini3
iPadMini4
iPadPro9Dot7Inch
iPadPro12Dot9Inch
iPad5

iPodTouch1Gen
iPodTouch2Gen
iPodTouch3Gen
iPodTouch4Gen
iPodTouch5Gen
iPodTouch6Gen

Simulator

Targetable screen sizes

Screen3Dot5inch
Screen4inch
Screen4Dot7inch
Screen5Dot5inch

Available iOS Version Finder methods

    + (BOOL)versionEqualTo:(NSString *)version;
    + (BOOL)versionGreaterThan:(NSString *)version;
    + (BOOL)versionGreaterThanOrEqualTo:(NSString *)version;
    + (BOOL)versionLessThan:(NSString *)version;
    + (BOOL)versionLessThanOrEqualTo:(NSString *)version;

Helpers

	  NSLog(@"%@", [SDVersion deviceVersionName:[SDVersion deviceVersion]]);
      /* e.g: Outputs 'iPad Air 2' */

      NSLog(@"%@", [SDVersion deviceSizeName:[SDVersion deviceSize]]);
      /* e.g: Outputs '4.7 inch' */

Or in Swift:

      let deviceVersionName = SDiOSVersion.deviceVersionName(SDiOSVersion.deviceVersion())
      let deviceSizeName = SDiOSVersion.deviceSizeName(SDiOSVersion.deviceSize())    

watchOS

Available methods

    + (DeviceVersion)deviceVersion;
	+ (DeviceSize)deviceSize;
	+ (NSString *)deviceName;

Targetable models

Apple Watch 38mm
Apple Watch 42mm
Apple Watch 38mm Series 1
Apple Watch 42mm Series 1
Apple Watch 38mm Series 2
Apple Watch 42mm Series 2

Simulator

Targetable screen sizes

Screen38mm
Screen42mm

Available watchOS Version Finder methods

    + (BOOL)versionEqualTo:(NSString *)version;
    + (BOOL)versionGreaterThan:(NSString *)version;
    + (BOOL)versionGreaterThanOrEqualTo:(NSString *)version;
    + (BOOL)versionLessThan:(NSString *)version;
    + (BOOL)versionLessThanOrEqualTo:(NSString *)version;

Helpers

	  NSLog(@"%@", [SDVersion deviceVersionName:[SDVersion deviceVersion]]);
      /* e.g: Outputs 'Apple Watch 42mm' */

      NSLog(@"%@", [SDVersion deviceSizeName:[SDVersion deviceSize]]);
      /* e.g: Outputs '42mm' */

tvOS

Available methods

    + (DeviceVersion)deviceVersion;
	+ (NSString *)deviceName;

Targetable models

Apple TV (4th Generation)

Simulator

Available tvOS Version Finder methods

    + (BOOL)versionEqualTo:(NSString *)version;
    + (BOOL)versionGreaterThan:(NSString *)version;
    + (BOOL)versionGreaterThanOrEqualTo:(NSString *)version;
    + (BOOL)versionLessThan:(NSString *)version;
    + (BOOL)versionLessThanOrEqualTo:(NSString *)version;

Helpers

	  NSLog(@"%@", [SDVersion deviceVersionName:[SDVersion deviceVersion]]);
      /* e.g: Outputs 'Apple TV (4th Generation)' */

Mac OS

      // Check for device model
      if ([SDVersion deviceVersion] == DeviceVersionIMac)
          NSLog(@"So you have a iMac? 💻");
      else if ([SDVersion deviceVersion] == DeviceVersionMacBookPro)
          NSLog(@"You're using a MacBook Pro.");

      // Check for screen size
      if ([SDVersion deviceSize] == Mac27Inch)
          NSLog(@"Whoah! You got a big ass 27 inch screen.");
      else if ([SDVersion deviceSize] == Mac21Dot5Inch)
          NSLog(@"You have a 21.5 inch screen.");

      // Check for screen resolution
      if ([SDVersion deviceScreenResolution] == DeviceScreenRetina)
          NSLog(@"Nice retina screen!");

      // Get screen resolution in pixels
      NSLog(@"%@", [SDVersion deviceScreenResolutionName:[SDVersion deviceScreenResolution]]);
      /* e.g: Outputs '{2880, 1800}' */

      // Check OSX Version (pass the minor version)
      if([SDVersion versionGreaterThanOrEqualTo:@"11"])
           NSLog(@"Looks like you are running OSX 10.11 El Capitan or 🆙.");

Available methods

    + (DeviceVersion)deviceVersion;
    + (NSString *)deviceVersionString;
    + (DeviceSize)deviceSize;
    + (NSSize)deviceScreenResolutionPixelSize;
    + (DeviceScreenResolution)deviceScreenResolution;

Targetable models

DeviceVersionIMac
DeviceVersionMacMini
DeviceVersionMacPro
DeviceVersionMacBook
DeviceVersionMacBookAir
DeviceVersionMacBookPro
DeviceVersionXserve

Targetable screen sizes

Mac27Inch
Mac24Inch
Mac21Dot5Inch
Mac20Inch
Mac17Inch
Mac15Inch
Mac13Inch
Mac12Inch
Mac11Inch

Targetable screen resolutions

DeviceScreenRetina,
DeviceScreenNoRetina

Available OSX Version Finder methods

    + (BOOL)versionEqualTo:(NSString *)version;
    + (BOOL)versionGreaterThan:(NSString *)version;
    + (BOOL)versionGreaterThanOrEqualTo:(NSString *)version;
    + (BOOL)versionLessThan:(NSString *)version;
    + (BOOL)versionLessThanOrEqualTo:(NSString *)version;
    /* 'v' must be the minor OS Version. e.g: OSX 10.9 - 'v' is 9 */

Helpers

      NSLog(@"%@", [SDVersion deviceSizeName:[SDVersion deviceSize]]);
      /* e.g: Outputs '15 inch' */

      NSLog(@"%@",[SDVersion deviceScreenResolutionName:[SDVersion deviceScreenResolution]])
      /* e.g: Outputs '{2880, 1800}' */

Used by

Who uses SDVersion

License

Usage is provided under the MIT License. See LICENSE for the full details.

Comments
  • 3.3 causes warning because of availability

    3.3 causes warning because of availability

    Availability is meant to annotate a method is available since certain version or deprecate since certain version. If anyone want to annotate a device's availability, they should define their own method or macro, otherwise compile the project will cause warnings.

    opened by sbhhbs 4
  • Typo in the readme

    Typo in the readme

    Instead of:

          // Get device name
          NSLog(@"%@", stringFromDeviceVersion([SDVersion deviceName]));
          /* e.g: Outputs 'iPhone 6 Plus' */
    

    I believe you meant to write:

          // Get device name
          NSLog(@"%@", stringFromDeviceVersion([SDVersion deviceVersion]));
          /* e.g: Outputs 'iPhone 6 Plus' */
    
    opened by Janglinator 4
  • [WIP] OSX compatibility

    [WIP] OSX compatibility

    That really not finish, but just a first implementation about it. Before going further, I prefer discuss the implementation with you. This PR contains just the basic to have the mac information by just copying your structure and adapt it to OSX. I didn't fill each device model information, but let links to apple documentation about it.

    That can work, but it's not pretty useful in order to handle and maintain both platforms. A better way would be to have an abstract the implementation, adapt it for each platforms, but the usage will be transparent whatever is the device. We can keep the same enums name, the same methods name (maybe add one or two following the case).

    Also, do we really want all the information about the mac: model, inch, retina, release year...? Once we have one, it's easy to have the others, so I don't think that will add a lot of work once we did it for the existing ones.

    Beside the architecture / implementation to do, an update of the README and the pod spec will be mandatory.

    Issue #20

    enhancement 
    opened by tbaranes 4
  • Can't import SDVersion

    Can't import SDVersion

    Hi,

    I use cocoapods to import this library and use use_frameworks! in my Podfile

    I'm not able to do

    import "SDVersion.h" in my bridging header nor am I able to import it directly in my class.

    In my other project, I don't use use_frameworks! and I can import SDVersion in my bridging header.

    opened by acegreen 3
  • Added Carthage support

    Added Carthage support

    What?

    I've created a new project that compiles frameworks in order to be used for Carthage. I've also updated the README explaining how to integrate the library using Carthage.

    Nice job @sebyddd :clap:

    opened by pepicrft 3
  • DeviceSize returns UnknownSize with landscape left screen

    DeviceSize returns UnknownSize with landscape left screen

    I am coding with Swift language and I have notice when I rotate the iOS simulator for any iPhone model SDiPhoneVersion.deviceSize() returns UnknownSize. That only happen when I rotate to landscape left. I have tried my code with one physical iPhone and I have obtained the same mistake

    opened by jcsobrino 3
  • [SDiPhoneVersion deviceSize] method's compatibility error above IOS8.0

    [SDiPhoneVersion deviceSize] method's compatibility error above IOS8.0

    According to the reference of the property [UIScreen mainScreen].bounds in ios8.0:

    Discussion

    This rectangle is specified in the current coordinate space, which takes into account any interface rotations in effect for the device. Therefore, the value of this property may change when the device rotates between portrait and landscape orientations.

    so the method call [SDiPhoneVersion deviceSize] is error above IOS8.0.In this method , to get the correct value of the screenHeight, code snippet should be added :

    //
    // After IOS8.0 [UIScreen mainScreen].bounds takes into account any interface rotations in effect for the device,
    // so the value of this property will change when the device rotate bewteen portrait and landscape.
    //
    if(iOSVersionGreaterThanOrEqualTo(@"8.0") && isLandscape){
        screenHeight = [UIScreen mainScreen].bounds.size.width;
    }
    
    opened by monjer 3
  • iOS: unknown device returns 0

    iOS: unknown device returns 0

    SDiOSVersion.deviceVersion:101 objectForKey returns nil, then integerValue converts that into a 0 Unfortunately that's the same code as "Simulator". Could we have a code for Unknown?

    opened by johnk73 2
  • How do I get the DeviceVersionName in swift

    How do I get the DeviceVersionName in swift

    Hello @sebyddd

    This issue is closed once in https://github.com/sebyddd/SDVersion/issues/47 Although, I have same problem for now and that closed issue looks not resolved yet.

    The following is the interface looks from Swift generated by Xcode. DeviceVersionNames is a tuple in Swift, so I can't get user friendly name from DeviceVersion.

    Did you support usage from Swift? Let me know if you so, and write down usage to README.

    Thanks.

    import UIKit
    
    //
    //  SDiOSVersion.h
    //  SDVersion
    //
    //  Copyright (c) 2016 Sebastian Dobrincu. All rights reserved.
    //
    
    public enum DeviceVersion : Int {
        
        case iPhone4
        case iPhone4S
        case iPhone5
        case iPhone5C
        case iPhone5S
        case iPhone6
        case iPhone6Plus
        case iPhone6S
        case iPhone6SPlus
        case iPhone7
        case iPhone7Plus
        case iPhoneSE
        
        case iPad1
        case iPad2
        case iPadMini
        case iPad3
        case iPad4
        case iPadAir
        case iPadMini2
        case iPadAir2
        case iPadMini3
        case iPadMini4
        case iPadPro12Dot9Inch
        case iPadPro9Dot7Inch
        
        case iPodTouch1Gen
        case iPodTouch2Gen
        case iPodTouch3Gen
        case iPodTouch4Gen
        case iPodTouch5Gen
        case iPodTouch6Gen
        
        case Simulator
    }
    
    public var DeviceVersionNames: (NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?, NSString?)
    
    public enum DeviceSize : Int {
        
        case UnknownSize
        case Screen3Dot5inch
        case Screen4inch
        case Screen4Dot7inch
        case Screen5Dot5inch
    }
    
    public var DeviceSizeNames: (NSString?, NSString?, NSString?, NSString?, NSString?)
    
    public class SDiOSVersion : NSObject {
        
        public class func deviceVersion() -> DeviceVersion
        public class func resolutionSize() -> DeviceSize
        public class func deviceSize() -> DeviceSize
        public class func deviceName() -> String!
        public class func isZoomed() -> Bool
    }
    
    
    opened by RyogaK 2
  • Do not contains iPhone SE

    Do not contains iPhone SE

    I use cocoapods to import SDVersion 2.6, but I found it's still not support iPhone SE, and did not contains any code about iPhone SE. I don't know why, thank you!!

    enhancement 
    opened by yzxcool123 2
  • Versions on Cocoapods/Github mismatch

    Versions on Cocoapods/Github mismatch

    Hi @sebyddd ,

    I installed SDVersion through Cocoapods which version is v2.6. But I noticed that it actually tagged as v2.5.2 on Github. Could you check it? Maybe you can later release the master version that supports iPhone SE.

    Thanks.

    opened by AzulesM 2
  • 更新到2022年设备

    更新到2022年设备

    pod 'SDVersion', git:'https://github.com/poholo/SDVersion.git'
    or 
    pod 'MCVersion'
    

    包含所有2022年的设备, 有问题请到https://github.com/poholo/SDVersion.git 提交issue

    opened by poholo 0
  • Add missing devices

    Add missing devices

    • iPhone XS

    • iPhone XS Max

    • iPhoneXʀ

    • iPhone 11

    • iPhone 11 Pro

    • iPhone 11 Pro Max

    • iPad 6

    • iPad 7

    • iPad mini 5

    • iPad Pro 11"

    • iPad Pro 12.9" 3rd gen

    • iPod touch 7th gen

    • Apple watch serie 4 42 mm

    • Apple watch serie 4 44 mm

    opened by Tibimac 0
  • IphoneX fix

    IphoneX fix

                              @"iPhone10,3" : @(iPhoneX),//iPhone X
                              @"iPhone10,6" : @(iPhoneX),//iPhone X GSM
                              @"iPhone11,2" : @(iPhoneX),//iPhone XS
                              @"iPhone11,4" : @(iPhoneX),//iPhone XS Max
                              @"iPhone11,6" : @(iPhoneX),//iPhone XS Max China
                              @"iPhone11,8" : @(iPhoneX),//iPhone XR
    
    opened by HevnChin 0
Releases(4.0)
Owner
Sebastian Dobrincu
I turn 🍵 and sleepless nights into art.
Sebastian Dobrincu
Easily communicate between iOS/OSX devices using BLE

BluetoothKit Easily communicate between iOS devices using BLE. Background Apple mostly did a great job with the CoreBluetooth API, but because it enca

Rasmus Høhndorf Hummelmose 2.1k Dec 29, 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
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
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
iOS & OSX Bluetooth library for RxSwift

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant. It's backed by RxSwift and CoreBluetooth and it prov

Polidea 1.3k Dec 16, 2022
Easily take a photo or video or choose from library

FDTake Easily take a photo or video or choose from library ?? Author's tip jar: https://amazon.com/hz/wishlist/ls/EE78A23EEGQB Usage To run the exampl

William Entriken 322 Nov 30, 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
🛰 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
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
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
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
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
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
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
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
Model framework for Cocoa and Cocoa Touch

Mantle Mantle makes it easy to write a simple model layer for your Cocoa or Cocoa Touch application. The Typical Model Object What's wrong with the wa

null 11.3k Dec 31, 2022