Skip to content
forked from cguess/SDVersion

📱 Lightweight Cocoa library for detecting the running device's model and screen size. 更新到2022devices iPhone14系列

License

Notifications You must be signed in to change notification settings

poholo/SDVersion

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

update log
4.3.7 增加2022年春季设备

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', git:'https://github.com/poholo/SDVersion.git'
        or 
        pod 'MCVersion'

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          
    iPhone7               
    iPhone7Plus           
    iPhone8               
    iPhone8Plus           
    iPhoneX               
    iPhoneSE              
    iPhoneXS              
    iPhoneXR              
    iPhoneXSMax
    iPhone11
    iPhone11Pro
    iPhone11ProMax
    iPhoneSE2
    iPhone12      
    iPhone12Pro   
    iPhone12ProMax
    iPhone12Mini  
    iPhone13      
    iPhone13Pro   
    iPhone13ProMax
    iPhone13Mini
    iPhoneSE3  
    iPhone14        
    iPhone14Plus    
    iPhone14Pro     
    iPhone14ProMax  




    iPad1                 
    iPad2                 
    iPadMini              
    iPad3                 
    iPad4                 
    iPadAir               
    iPadMini2             
    iPadAir2              
    iPadMini3             
    iPadMini4             
    iPadPro12Dot9Inch     
    iPadPro9Dot7Inch      
    iPad5                     
    iPadPro12Dot9Inch2Gen 
    iPadPro10Dot5Inch     
    iPadPro11Inch         
    iPadAir3
    iPad6
    iPadPro12Dot9Inch4Gen
    iPadPro11Inch2Gen 
    iPad8   
    iPadAir4
    iPadMini6             
    iPadPro12Dot9Inch5Gen 
    iPadPro11Inch3Gen     
    iPad9 
    iPadAir5                    
                  
    iPodTouch1Gen         
    iPodTouch2Gen         
    iPodTouch3Gen         
    iPodTouch4Gen         
    iPodTouch5Gen         
    iPodTouch6Gen
    iPodTouch6Gen   
    iPodTouch7Gen   

    Simulator

Targetable screen sizes

    Screen3Dot5inch,
    Screen4inch    ,
    Screen4Dot7inch,
    Screen5Dot5inch,
    Screen5Dot4inch,
    Screen5Dot8inch,
    Screen6Dot1inch,
    Screen6Dot5inch,
    Screen6Dot7inch,
    Screen8Dot3inch,
    Screen9Dot7inch,
    Screen10Dot2inch,
    Screen10Dot9inch,
    Screen11inch,
    Screen12Dot9inch

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
    Apple Watch 38mm Series 3
    Apple Watch 42mm Series 3
    Apple Watch 40mm Series 4
    Apple Watch 44mm Series 4
    Apple Watch 40mm Series 5
    Apple Watch 44mm Series 5
    Apple Watch 40mm SE     
    Apple Watch 44mm SE  
    Apple Watch 40mm Series 6
    Apple Watch 44mm Series 6   
    Apple Watch 41mm Series7
    Apple Watch 45mm Series7
    AppleWatch40mmSE2     ,
    AppleWatch44mmSE2     ,
    AppleWatch41mmSeries8 ,
    AppleWatch45mmSeries8 ,
    AppleWatch49mmUltra ,
    
    Simulator

Targetable screen sizes

    Screen38mm
    Screen40mm
    Screen41mm
    Screen42mm
    Screen44mm
    Screen45mm
    Screen49mm

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)
Apple TV 4K
Apple TV 4K(2nd Generation)
Apple TV 4K(2nd Generation 1080p)

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.

About

📱 Lightweight Cocoa library for detecting the running device's model and screen size. 更新到2022devices iPhone14系列

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 91.2%
  • Ruby 6.2%
  • Swift 2.6%