CheckDevice 1.0.5

CheckDevice 1.0.5

Uğur Ethem AYDIN维护。



CheckDevice✔️

Tweet

CheckDevice

language

Version License Platform

CI Status

如何检测iOS设备和屏幕尺寸?

CheckDevice检测当前设备的型号和屏幕尺寸。
CheckDevice.size()

简化并居中

您也可以使用以下代码检查设备类型iPhone:

CheckDevice.isPhone() 

CocoaPods或Swift包管理器(SPM)

CheckDevice支持CocoaPods和SPM。

CocoaPods

CocoaPods 是Xcode项目的依赖管理器。要使用CocoaPods中的CheckDevice,只需将以下行添加到您的PodFile中即可

pod 'CheckDevice'

然后运行: $ pod install

Swift Package Manager

Swift Package Manager自动分发Swift代码。要使用SPM中的CheckDevice,请将依赖添加到您的Package.swift文件中

let package = Package(
    dependencies: [
        .package(url: "https://github.com/ugurethemaydin/CheckDevice.git", ...)
    ]
)

Carthage

Carthage不受支持。

使用方法

检测当前设备并记录日志

CheckDevice.current()

iOS

设备版本

func myFunc() {
        /*** Display the device version ***/
        switch CheckDevice.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")
            case .iPhone11:             print("It's an iPhone 11")            
            case .iPhone11Pro:          print("It's an iPhone 11")                        
            case .iPhone11Pro_Max:      print("It's an iPhone 11 Pro Max")                        
            case .iPhone11Pro_Max:      print("It's an iPhone 11 Pro Max")                                    
            case .iPhoneSE2:            print("It's an iPhone SE 2 Gen")                                                
            case .iPhone12Mini:         print("It's an iPhone 12 Mini")                                                            
            case .iPhone12:             print("It's an iPhone 12")                                                                        
            case .iPhone12Pro:          print("It's an iPhone 12 Pro")                                                                                    
            case .iPhone12ProMax:       print("It's an iPhone 12 Pro Max")                                                                                                
        

            /*** 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 .iPad7:           print("It's an iPad 7")            
            
            /*** iPadAir ***/
            case .iPadAir:         print("It's an iPad Air")
            case .iPadAir2:        print("It's an iPad Air 2")
            
            
            /*** iPadMini ***/
            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")
            
            
            /*** iPadPro ***/
            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")
            case .iPodTouch7Gen: print("It's a iPod touch generation 7")            
            
            
            /*** Watch ***/
            case .WatchOriginal38mm: print("It's a Apple Watch Original 38MM")            
            case .WatchOriginal42mm: print("It's a Apple Watch Original 42MM")                        
            
            /*** All watch alternative included... Some examples ***/
            case .Watch1Gen38mm: print("It's a Apple Watch 1 38MM")                                    
            case .Watch2Gen42mm: print("It's a Apple Watch 2 42MM")                                                
            case .Watch4Gen40mm: print("It's a Apple Watch 4 38MM")                                                            
            case .Watch6Gen40mm: print("It's a Apple Watch 6 40MM")        
            case .WatchSE44mm: print("It's a Apple Watch SE 44MM")                                                                                    
           
           
           
            /*** Simulator ***/
            case .Simulator:    print("It's a Simulator")

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

设备屏幕尺寸

func myFunc() {
        /*** Display the device screen size ***/
        switch CheckDevice.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_4Inch:  print("It's a 5.4 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.5 inch screen")
            case .screen6_7Inch:  print("It's a 6.7 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")
        }
}

设备类型

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

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

Mac

Mac版本

func myFunc() {
        /*** Display the mac version ***/
        switch CheckDevice.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屏幕尺寸

func myFunc() {
        /*** Display the mac screen size ***/
        switch CheckDevice.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")
        }
}

助手

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

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

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

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

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

作者

Uğur Ethem AYDIN, [email protected] @ugurethemaydin

许可协议

CheckDevice 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。