diff --git a/.gitignore b/.gitignore index 44f6561..35c6e13 100755 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,10 @@ DerivedData +SDVersion-Demo/.idea/.gitignore +SDVersion-Demo/.idea/.name +SDVersion-Demo/.idea/encodings.xml +SDVersion-Demo/.idea/modules.xml +SDVersion-Demo/.idea/SDVersion-Demo.iml +SDVersion-Demo/.idea/vcs.xml +SDVersion-Demo/.idea/xcode.xml diff --git a/MCVersion.podspec b/MCVersion.podspec new file mode 100755 index 0000000..25c48a0 --- /dev/null +++ b/MCVersion.podspec @@ -0,0 +1,44 @@ +Pod::Spec.new do |s| + + # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # These will help people to find your library, and whilst it + # can feel like a chore to fill in it's definitely to your advantage. The + # summary should be tweet-length, and the description more in depth. + # + + s.name = "MCVersion" + s.version = "4.3.8" + s.summary = "Lightweight Cocoa library for detecting the running device's model and screen size. 作者不更新,我的一些库依赖SDVersion,故发一个MC版本,见谅. 22春季设备更新" + s.homepage = "https://github.com/poholo/SDVersion" + s.screenshots = "https://dl.dropboxusercontent.com/s/bmfjwfe2ngnivwn/sdversion.png?dl=0" + + + # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Licensing your code is important. See http://choosealicense.com for more info. + # CocoaPods will detect a license file if there is a named LICENSE* + # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. + # + + s.license = "MIT" + s.license = { :type => "MIT", :file => "LICENSE" } + s.author = { "Sebastian Dobrincu" => "me@dobrincu.co" } + s.platform = :ios + s.platform = :osx + s.platform = :watchos + s.platform = :tvos + s.ios.deployment_target = '10.0' + s.osx.deployment_target = '10.9' + s.watchos.deployment_target = '2.0' + s.tvos.deployment_target = '9.0' + s.ios.source_files = "SDVersion/SDiOSVersion/*.{h,m}" + s.osx.source_files = "SDVersion/SDMacVersion/*.{h,m}" + s.watchos.source_files = "SDVersion/SDwatchOSVersion/*.{h,m}" + s.tvos.source_files = "SDVersion/SDtvOSVersion/*.{h,m}" + s.source = { :git => 'https://github.com/poholo/SDVersion.git', :tag => "#{s.version}" } + s.source_files = "SDVersion/*.{h,m}" + + s.requires_arc = true + +end diff --git a/README.md b/README.md index a38a2ac..8520073 100755 --- a/README.md +++ b/README.md @@ -32,6 +32,12 @@ SDVersion supports iOS, watchOS, tvOS, and macOS. Browse through the implementat

+``` +update log +4.3.7 增加2022年春季设备 + +``` + ## How it works ```objective-c @@ -111,10 +117,14 @@ CocoaPods is a dependency manager for Objective-C, which automates and simplifie ### Podfile ```ruby - pod 'SDVersion' + pod 'SDVersion', git:'https://github.com/poholo/SDVersion.git' + or + pod 'MCVersion' ``` + + ## iOS ### Available methods @@ -128,46 +138,105 @@ CocoaPods is a dependency manager for Objective-C, which automates and simplifie + (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 +``` + 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 +``` + Screen3Dot5inch, + Screen4inch , + Screen4Dot7inch, + Screen5Dot5inch, + Screen5Dot4inch, + Screen5Dot8inch, + Screen6Dot1inch, + Screen6Dot5inch, + Screen6Dot7inch, + Screen8Dot3inch, + Screen9Dot7inch, + Screen10Dot2inch, + Screen10Dot9inch, + Screen11inch, + Screen12Dot9inch +``` + + ### Available iOS Version Finder methods ```objective-c + (BOOL)versionEqualTo:(NSString *)version; @@ -196,22 +265,48 @@ Or in Swift: ### Available methods ```objective-c + (DeviceVersion)deviceVersion; - + (DeviceSize)deviceSize; - + (NSString *)deviceName; + + (DeviceSize)deviceSize; + + (NSString *)deviceName; ``` ### Targetable models - Apple Watch 38mm +``` + 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 ```objective-c @@ -239,8 +334,11 @@ Or in Swift: + (NSString *)deviceName; ``` ### Targetable models - Apple TV (4th Generation) - + Apple TV (4th Generation) + Apple TV 4K + Apple TV 4K(2nd Generation) + Apple TV 4K(2nd Generation 1080p) + Simulator ### Available tvOS Version Finder methods @@ -254,7 +352,7 @@ Or in Swift: ### Helpers ```objective-c - NSLog(@"%@", [SDVersion deviceVersionName:[SDVersion deviceVersion]]); + NSLog(@"%@", [SDVersion deviceVersionName:[SDVersion deviceVersion]]); /* e.g: Outputs 'Apple TV (4th Generation)' */ ``` @@ -294,28 +392,34 @@ Or in Swift: + (DeviceScreenResolution)deviceScreenResolution; ``` ### Targetable models - DeviceVersionIMac - DeviceVersionMacMini - DeviceVersionMacPro - DeviceVersionMacBook - DeviceVersionMacBookAir - DeviceVersionMacBookPro - DeviceVersionXserve +``` + DeviceVersionIMac + DeviceVersionMacMini + DeviceVersionMacPro + DeviceVersionMacBook + DeviceVersionMacBookAir + DeviceVersionMacBookPro + DeviceVersionXserve +``` ### Targetable screen sizes +``` Mac27Inch - Mac24Inch - Mac21Dot5Inch - Mac20Inch - Mac17Inch - Mac15Inch - Mac13Inch - Mac12Inch - Mac11Inch + Mac24Inch + Mac21Dot5Inch + Mac20Inch + Mac17Inch + Mac15Inch + Mac13Inch + Mac12Inch + Mac11Inch +``` ### Targetable screen resolutions +``` DeviceScreenRetina, - DeviceScreenNoRetina + DeviceScreenNoRetina +``` ### Available OSX Version Finder methods ```objective-c diff --git a/SDVersion-Demo/SDMacVersion/Base.lproj/Main.storyboard b/SDVersion-Demo/SDMacVersion/Base.lproj/Main.storyboard index e5196f0..7430105 100755 --- a/SDVersion-Demo/SDMacVersion/Base.lproj/Main.storyboard +++ b/SDVersion-Demo/SDMacVersion/Base.lproj/Main.storyboard @@ -1,7 +1,9 @@ - - + + - + + + @@ -650,11 +652,14 @@ - + + + + @@ -662,7 +667,7 @@ - + @@ -676,63 +681,70 @@ + + - - - + - + - - + - + - - + - + - - + - + + + + + + + + + + + + - diff --git a/SDVersion-Demo/SDMacVersion/Images.xcassets/logo.imageset/SDVersion-logo.png b/SDVersion-Demo/SDMacVersion/Images.xcassets/logo.imageset/SDVersion-logo.png index 584ebb1..a29dc1f 100644 Binary files a/SDVersion-Demo/SDMacVersion/Images.xcassets/logo.imageset/SDVersion-logo.png and b/SDVersion-Demo/SDMacVersion/Images.xcassets/logo.imageset/SDVersion-logo.png differ diff --git a/SDVersion-Demo/SDVersion.xcodeproj/project.pbxproj b/SDVersion-Demo/SDVersion.xcodeproj/project.pbxproj index 04680a4..505e6a3 100755 --- a/SDVersion-Demo/SDVersion.xcodeproj/project.pbxproj +++ b/SDVersion-Demo/SDVersion.xcodeproj/project.pbxproj @@ -136,6 +136,9 @@ 1FE53CD41D3FF491005739A5 /* SDtvOSVersionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SDtvOSVersionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 1FE53CD81D3FF491005739A5 /* SDtvOSVersionTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDtvOSVersionTests.m; sourceTree = ""; }; 1FE53CDA1D3FF491005739A5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 337CEC232703285D0086B6DC /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; + 337CEC24270329EC0086B6DC /* SDVersion.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; name = SDVersion.podspec; path = ../SDVersion.podspec; sourceTree = ""; }; + 337CEC25270329F60086B6DC /* MCVersion.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; name = MCVersion.podspec; path = ../MCVersion.podspec; sourceTree = ""; }; 9A6DB5DE1B8E82D00065EA11 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 9A6DB5DF1B8E82D00065EA11 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 9A6DB5E11B8E82D00065EA11 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; @@ -323,6 +326,9 @@ 9AA6623F19BFABFC0055042F = { isa = PBXGroup; children = ( + 337CEC25270329F60086B6DC /* MCVersion.podspec */, + 337CEC24270329EC0086B6DC /* SDVersion.podspec */, + 337CEC232703285D0086B6DC /* README.md */, 9A95DA931B853CFF00F96CB5 /* SDVersion */, 9A6DB5DD1B8E82D00065EA11 /* SDiOSVersion */, 9A6DB5F01B8E82E00065EA11 /* SDiOSVersionTests */, @@ -543,7 +549,7 @@ 9AA6624019BFABFC0055042F /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0910; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Sebastian Dobrincu"; TargetAttributes = { 1FC73CFF1D244B87005F81DA = { @@ -564,7 +570,7 @@ }; 9AA6626019BFABFC0055042F = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0820; + LastSwiftMigration = 1000; TestTargetID = 9AA6624719BFABFC0055042F; }; E2D975171B8265DF00675936 = { @@ -582,6 +588,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -974,12 +981,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -1027,12 +1036,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -1070,11 +1081,12 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; IBSC_WARNINGS = YES; INFOPLIST_FILE = SDiOSVersion/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.dobrincusebastian.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -1086,11 +1098,12 @@ CODE_SIGN_IDENTITY = ""; IBSC_WARNINGS = YES; INFOPLIST_FILE = SDiOSVersion/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.dobrincusebastian.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; @@ -1114,7 +1127,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "SDiOSVersionTests/SDiOSVersionTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SDiOSVersion.app/SDiOSVersion"; }; name = Debug; @@ -1134,7 +1148,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.dobrincusebastian.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "SDiOSVersionTests/SDiOSVersionTests-Bridging-Header.h"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SDiOSVersion.app/SDiOSVersion"; }; name = Release; @@ -1153,7 +1168,7 @@ ); INFOPLIST_FILE = SDMacVersion/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.13; PRODUCT_BUNDLE_IDENTIFIER = "com.dobrincusebastian.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -1171,7 +1186,7 @@ GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = SDMacVersion/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.13; PRODUCT_BUNDLE_IDENTIFIER = "com.dobrincusebastian.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; diff --git a/SDVersion-Demo/SDVersion.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SDVersion-Demo/SDVersion.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/SDVersion-Demo/SDVersion.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/SDVersion-Demo/SDiOSVersion/AppDelegate.m b/SDVersion-Demo/SDiOSVersion/AppDelegate.m index e145893..2aaf163 100755 --- a/SDVersion-Demo/SDiOSVersion/AppDelegate.m +++ b/SDVersion-Demo/SDiOSVersion/AppDelegate.m @@ -12,7 +12,11 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. - [[UIApplication sharedApplication] setStatusBarHidden:YES]; + + #if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 + [[UIApplication sharedApplication] setStatusBarHidden:YES]; + #endif + return YES; } diff --git a/SDVersion-Demo/SDiOSVersion/Base.lproj/LaunchScreen.xib b/SDVersion-Demo/SDiOSVersion/Base.lproj/LaunchScreen.xib index 0a514d3..5ba066f 100755 --- a/SDVersion-Demo/SDiOSVersion/Base.lproj/LaunchScreen.xib +++ b/SDVersion-Demo/SDiOSVersion/Base.lproj/LaunchScreen.xib @@ -1,8 +1,10 @@ - - + + + - - + + + @@ -11,14 +13,14 @@ - - + diff --git a/SDVersion-Demo/SDiOSVersion/Base.lproj/Main.storyboard b/SDVersion-Demo/SDiOSVersion/Base.lproj/Main.storyboard index 0846f29..2cceb87 100755 --- a/SDVersion-Demo/SDiOSVersion/Base.lproj/Main.storyboard +++ b/SDVersion-Demo/SDiOSVersion/Base.lproj/Main.storyboard @@ -1,11 +1,28 @@ - - + + + - - + + + + + + + + + + + + + + + + + + @@ -19,57 +36,35 @@ - + + + + - + + - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - + @@ -79,10 +74,10 @@ - + - + diff --git a/SDVersion-Demo/SDiOSVersion/Images.xcassets/logo.imageset/logo.png b/SDVersion-Demo/SDiOSVersion/Images.xcassets/logo.imageset/logo.png index 660371b..986d962 100644 Binary files a/SDVersion-Demo/SDiOSVersion/Images.xcassets/logo.imageset/logo.png and b/SDVersion-Demo/SDiOSVersion/Images.xcassets/logo.imageset/logo.png differ diff --git a/SDVersion-Demo/SDiOSVersion/ViewController.m b/SDVersion-Demo/SDiOSVersion/ViewController.m index 0f1eb30..60f2954 100755 --- a/SDVersion-Demo/SDiOSVersion/ViewController.m +++ b/SDVersion-Demo/SDiOSVersion/ViewController.m @@ -10,8 +10,13 @@ @implementation ViewController +- (BOOL)prefersStatusBarHidden { + return true; +} + - (void)viewDidLoad { [super viewDidLoad]; + self.title = @"SDVersion!!!!!!!!!!"; // Get device name as NSString self.iphoneVersionLabel.text = [self.iphoneVersionLabel.text stringByAppendingString:[SDVersion deviceNameString]]; @@ -36,6 +41,12 @@ - (void)viewDidLoad { NSLog(@"Your screen size is 4.7 inches"); else if([SDVersion deviceSize] == Screen5Dot5inch) NSLog(@"Your screen size is 5.5 inches"); + else if([SDVersion deviceSize] == Screen5Dot8inch) + NSLog(@"Your screen size is 5.8 inches"); + else if([SDVersion deviceSize] == Screen6Dot1inch) + NSLog(@"Your screen size is 6.1 inches"); + else if([SDVersion deviceSize] == Screen6Dot5inch) + NSLog(@"Your screen size is 6.5 inches"); if ([SDVersion isZoomed]) { NSLog(@"Your device is in Zoom Mode!"); @@ -48,5 +59,4 @@ - (void)viewDidLoad { NSLog(@"You're on iOS 9.1 or below! ⏳"); } - @end diff --git a/SDVersion-Demo/SDtvOSVersion/ViewController.m b/SDVersion-Demo/SDtvOSVersion/ViewController.m index a2e0f78..730c256 100644 --- a/SDVersion-Demo/SDtvOSVersion/ViewController.m +++ b/SDVersion-Demo/SDtvOSVersion/ViewController.m @@ -24,6 +24,8 @@ - (void)viewDidLoad { // Get device name as NSString self.tvVersionLabel.text = [self.tvVersionLabel.text stringByAppendingString:[SDtvOSVersion deviceVersionName:[SDtvOSVersion deviceVersion]]]; + NSLog([SDtvOSVersion deviceName]); + // Check for device model if ([SDtvOSVersion deviceVersion] == AppleTV4) NSLog(@"You got the fourth-generation Apple TV. Nice!"); diff --git a/SDVersion.podspec b/SDVersion.podspec index 4902f0f..50c6e75 100755 --- a/SDVersion.podspec +++ b/SDVersion.podspec @@ -8,9 +8,9 @@ Pod::Spec.new do |s| # s.name = "SDVersion" - s.version = "4.3.2" - s.summary = "Lightweight Cocoa library for detecting the running device's model and screen size." - s.homepage = "https://github.com/sebyddd/SDVersion" + s.version = "4.3.5" + s.summary = "Lightweight Cocoa library for detecting the running device's model and screen size. 作者不更新,我的一些库依赖SDVersion,故发一个MC版本,见谅" + s.homepage = "https://github.com/poholo/SDVersion" s.screenshots = "https://dl.dropboxusercontent.com/s/bmfjwfe2ngnivwn/sdversion.png?dl=0" @@ -21,14 +21,14 @@ Pod::Spec.new do |s| # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. # - s.license = "MIT (example)" + s.license = "MIT" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "Sebastian Dobrincu" => "me@dobrincu.co" } s.platform = :ios s.platform = :osx s.platform = :watchos s.platform = :tvos - s.ios.deployment_target = '7.0' + s.ios.deployment_target = '10.0' s.osx.deployment_target = '10.9' s.watchos.deployment_target = '2.0' s.tvos.deployment_target = '9.0' @@ -36,7 +36,7 @@ Pod::Spec.new do |s| s.osx.source_files = "SDVersion/SDMacVersion/*.{h,m}" s.watchos.source_files = "SDVersion/SDwatchOSVersion/*.{h,m}" s.tvos.source_files = "SDVersion/SDtvOSVersion/*.{h,m}" - s.source = { :git => 'https://github.com/sebyddd/SDVersion.git', :tag => "#{s.version}" } + s.source = { :git => 'https://github.com/poholo/SDVersion.git', :tag => "#{s.version}" } s.source_files = "SDVersion/*.{h,m}" s.requires_arc = true diff --git a/SDVersion/SDiOSVersion/SDiOSVersion.h b/SDVersion/SDiOSVersion/SDiOSVersion.h index 216e53b..22cdfcc 100755 --- a/SDVersion/SDiOSVersion/SDiOSVersion.h +++ b/SDVersion/SDiOSVersion/SDiOSVersion.h @@ -26,38 +26,84 @@ typedef NS_ENUM(NSInteger, DeviceVersion){ iPhone8Plus = 15, iPhoneX = 16, iPhoneSE = 17, + iPhoneXS = 18, + iPhoneXR = 19, + iPhoneXSMax = 20, + iPhone11 = 21, + iPhone11Pro = 22, + iPhone11ProMax = 23, + iPhoneSE2 = 24, + iPhone12 = 25, + iPhone12Pro = 26, + iPhone12ProMax = 27, + iPhone12Mini = 28, + iPhone13 = 29, + iPhone13Pro = 30, + iPhone13ProMax = 31, + iPhone13Mini = 32, + iPhoneSE3 = 33, + iPhone14 = 34, + iPhone14Plus = 35, + iPhone14Pro = 36, + iPhone14ProMax = 37, - iPad1 = 18, - iPad2 = 19, - iPadMini = 20, - iPad3 = 21, - iPad4 = 22, - iPadAir = 23, - iPadMini2 = 24, - iPadAir2 = 25, - iPadMini3 = 26, - iPadMini4 = 27, - iPadPro12Dot9Inch = 28, - iPadPro9Dot7Inch = 29, - iPad5 = 30, - iPadPro12Dot9Inch2Gen = 31, - iPadPro10Dot5Inch = 32, - iPodTouch1Gen = 33, - iPodTouch2Gen = 34, - iPodTouch3Gen = 35, - iPodTouch4Gen = 36, - iPodTouch5Gen = 37, - iPodTouch6Gen = 38 + iPad1 = 100, + iPad2 = 101, + iPadMini = 102, + iPad3 = 103, + iPad4 = 104, + iPadAir = 105, + iPadMini2 = 106, + iPadAir2 = 107, + iPadMini3 = 108, + iPadMini4 = 109, + iPadPro12Dot9Inch = 110, + iPadPro9Dot7Inch = 111, + iPad5 = 112, + iPad6 = 113, + iPadPro12Dot9Inch2Gen = 114, + iPadPro10Dot5Inch = 115, + iPadPro11Inch = 116, + iPadAir3 = 117, + iPad7 = 118, + iPadMini5 = 119, + iPadPro12Dot9Inch4Gen = 120, + iPadPro11Inch2Gen = 121, + iPad8 = 122, + iPadAir4 = 123, + iPadMini6 = 124, + iPadPro12Dot9Inch5Gen = 125, + iPadPro11Inch3Gen = 126, + iPad9 = 127, + iPadAir5 = 128, + + iPodTouch1Gen = 200, + iPodTouch2Gen = 201, + iPodTouch3Gen = 202, + iPodTouch4Gen = 203, + iPodTouch5Gen = 204, + iPodTouch6Gen = 205, + iPodTouch7Gen = 206, }; typedef NS_ENUM(NSInteger, DeviceSize){ UnknownSize = 0, - Screen3Dot5inch = 1, - Screen4inch = 2, - Screen4Dot7inch = 3, - Screen5Dot5inch = 4, - Screen5Dot8inch = 5 + Screen3Dot5inch, + Screen4inch , + Screen4Dot7inch, + Screen5Dot5inch, + Screen5Dot4inch, + Screen5Dot8inch, + Screen6Dot1inch, + Screen6Dot5inch, + Screen6Dot7inch, + Screen8Dot3inch, + Screen9Dot7inch, + Screen10Dot2inch, + Screen10Dot9inch, + Screen11inch, + Screen12Dot9inch }; @interface SDiOSVersion : NSObject diff --git a/SDVersion/SDiOSVersion/SDiOSVersion.m b/SDVersion/SDiOSVersion/SDiOSVersion.m index fcf181c..1956e3a 100755 --- a/SDVersion/SDiOSVersion/SDiOSVersion.m +++ b/SDVersion/SDiOSVersion/SDiOSVersion.m @@ -48,6 +48,29 @@ + (NSDictionary*)deviceNamesByCode @"iPhone10,5" : @(iPhone8Plus), @"iPhone10,3" : @(iPhoneX), @"iPhone10,6" : @(iPhoneX), + @"iPhone11,8" : @(iPhoneXR), + @"iPhone11,2" : @(iPhoneXS), + @"iPhone11,4" : @(iPhoneXSMax), + @"iPhone11,6" : @(iPhoneXSMax), + @"iPhone12,1" : @(iPhone11), + @"iPhone12,3" : @(iPhone11Pro), + @"iPhone12,5" : @(iPhone11ProMax), + @"iPhone12,8" : @(iPhoneSE2), + @"iPhone13,2" : @(iPhone12), + @"iPhone13,3" : @(iPhone12Pro), + @"iPhone13,4" : @(iPhone12ProMax), + @"iPhone13,1" : @(iPhone12Mini), + + @"iPhone14,5" : @(iPhone13), + @"iPhone14,2" : @(iPhone13Pro), + @"iPhone14,3" : @(iPhone13ProMax), + @"iPhone14,4" : @(iPhone13Mini), + @"iPhone14,6" : @(iPhoneSE3), + @"iPhone14,7" : @(iPhone14), + @"iPhone14,8" : @(iPhone14Plus), + @"iPhone15,2" : @(iPhone14Pro), + @"iPhone15,3" : @(iPhone14ProMax), + @"i386" : @(Simulator), @"x86_64" : @(Simulator), @@ -89,6 +112,33 @@ + (NSDictionary*)deviceNamesByCode @"iPad7,2" : @(iPadPro12Dot9Inch2Gen), @"iPad7,3" : @(iPadPro10Dot5Inch), @"iPad7,4" : @(iPadPro10Dot5Inch), + @"iPad7,5" : @(iPad6), + @"iPad7,6" : @(iPad6), + @"iPad7,11" : @(iPad7), + @"iPad7,12" : @(iPad7), + @"iPad8,1" : @(iPadPro11Inch), + @"iPad8,2" : @(iPadPro11Inch), + @"iPad8,3" : @(iPadPro11Inch), + @"iPad8,4" : @(iPadPro11Inch), + @"iPad8,5" : @(iPadPro12Dot9Inch), + @"iPad8,6" : @(iPadPro12Dot9Inch), + @"iPad8,7" : @(iPadPro12Dot9Inch), + @"iPad8,8" : @(iPadPro12Dot9Inch), + @"iPad8,9" : @(iPadPro11Inch2Gen), + @"iPad8,12" : @(iPadPro12Dot9Inch4Gen), + @"iPad11,1" : @(iPadMini5), + @"iPad11,2" : @(iPadMini5), + @"iPad11,3" : @(iPadAir3), + @"iPad11,4" : @(iPadAir3), + @"iPad11,7" : @(iPad8), + @"iPad13,2" : @(iPadAir4), + @"iPad14,1" : @(iPadMini6), + @"iPad13,10": @(iPadPro12Dot9Inch5Gen), + @"iPad13,5" : @(iPadPro11Inch3Gen), + @"iPad12,2" : @(iPad9), + @"iPad13,17": @(iPadAir5), + + //iPods @"iPod1,1" : @(iPodTouch1Gen), @@ -96,7 +146,9 @@ + (NSDictionary*)deviceNamesByCode @"iPod3,1" : @(iPodTouch3Gen), @"iPod4,1" : @(iPodTouch4Gen), @"iPod5,1" : @(iPodTouch5Gen), - @"iPod7,1" : @(iPodTouch6Gen)}; + @"iPod7,1" : @(iPodTouch6Gen), + @"iPod9,1" : @(iPodTouch7Gen) + }; #pragma clang diagnostic pop }); @@ -105,10 +157,18 @@ + (NSDictionary*)deviceNamesByCode + (DeviceVersion)deviceVersion { - struct utsname systemInfo; - uname(&systemInfo); - NSString *code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; + NSString *code = nil; + +#if TARGET_OS_SIMULATOR + code = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; +#endif // TARGET_OS_SIMULATOR + if (code == nil) { + struct utsname systemInfo; + uname(&systemInfo); + code = [NSString stringWithCString:systemInfo.machine + encoding:NSUTF8StringEncoding]; + } DeviceVersion version = (DeviceVersion)[[self.deviceNamesByCode objectForKey:code] integerValue]; return version; @@ -116,14 +176,30 @@ + (DeviceVersion)deviceVersion + (DeviceSize)resolutionSize { - CGFloat screenHeight = 0; - + DeviceSize deviseSize; + + // iOS > 8 does a better differentiation by using UIScreen.nativeBounds, + // this was not available in earlier versions. The nice thing is that nativeBounds + // really only matters on newer devices (iPhone R and Xs Max report the same UIScreen.bounds value) if ([SDiOSVersion versionGreaterThanOrEqualTo:@"8"]) { - screenHeight = MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width); + deviseSize = [self resolutionSizeForIOSGreaterThan8]; } else { - screenHeight = [[UIScreen mainScreen] bounds].size.height; + deviseSize = [self resolutionSizeForIOSLessThan8]; } + return deviseSize; +} + ++ (DeviceSize)resolutionSizeForIOSLessThan8 +{ + if ([SDiOSVersion versionGreaterThanOrEqualTo:@"8"]) { + [NSException raise:@"Wrong iOS Version For Checking" format:@"The version of iOS %ld is greater than iOS 8 which is required for this function", (long)[SDiOSVersion version]]; + } + + CGFloat screenHeight = 0; + + screenHeight = [[UIScreen mainScreen] bounds].size.height; + if (screenHeight == 480) { return Screen3Dot5inch; } else if(screenHeight == 568) { @@ -134,8 +210,54 @@ + (DeviceSize)resolutionSize return Screen5Dot5inch; } else if (screenHeight == 812) { return Screen5Dot8inch; + } else if (screenHeight == 896) { + return Screen6Dot1inch; } else - return UnknownSize; + return UnknownSize; +} + ++ (DeviceSize)resolutionSizeForIOSGreaterThan8 +{ + if ([SDiOSVersion versionLessThan:@"8"]) { + [NSException raise:@"Wrong iOS Version For Checking" format:@"The version of iOS %ld is less than iOS 8 which is required for this function", (long)[SDiOSVersion version]]; + } + + CGFloat screenHeight = 0; + + screenHeight = [[UIScreen mainScreen] nativeBounds].size.height; + + if (screenHeight == 480 || screenHeight == 960) { + return Screen3Dot5inch; + } else if(screenHeight == 1136) { + return Screen4inch; + } else if(screenHeight == 1334) { + return Screen4Dot7inch; + } else if(screenHeight == 2208) { + return Screen5Dot5inch; + } else if(screenHeight == 2340) { + return Screen5Dot4inch; + } else if (screenHeight == 2436) { + return Screen5Dot8inch; + } else if (screenHeight == 1792 || screenHeight == 2532 || screenHeight == 2556) { + return Screen6Dot1inch; + } else if (screenHeight == 2688) { + return Screen6Dot5inch; + } else if (screenHeight == 2778 || screenHeight == 2796) { + return Screen6Dot7inch; + } else if (screenHeight == 2266) { + return Screen8Dot3inch; + } else if (screenHeight == 2048) { + return Screen9Dot7inch; + } else if (screenHeight == 2160) { + return Screen10Dot2inch; + } else if (screenHeight == 2360) { + return Screen10Dot9inch; + } else if (screenHeight == 2388) { + return Screen11inch; + } else if (screenHeight == 2732) { + return Screen12Dot9inch; + } + return UnknownSize; } + (DeviceSize)deviceSize @@ -158,8 +280,19 @@ + (NSString *)deviceSizeName:(DeviceSize)deviceSize @(Screen3Dot5inch) : @"3.5 inch", @(Screen4inch) : @"4 inch", @(Screen4Dot7inch) : @"4.7 inch", + @(Screen5Dot4inch) : @"5.4 inch", @(Screen5Dot5inch) : @"5.5 inch", @(Screen5Dot8inch) : @"5.8 inch", + @(Screen6Dot1inch) : @"6.1 inch", + @(Screen6Dot5inch) : @"6.5 inch", + @(Screen6Dot7inch) : @"6.7 inch", + @(Screen8Dot3inch) : @"8.3 inch", + @(Screen9Dot7inch) : @"9.7 inch", + @(Screen10Dot2inch): @"10.2 inch", + @(Screen10Dot9inch): @"10.9 inch", + @(Screen11inch) : @"11 inch", + @(Screen12Dot9inch): @"12.9 inch", + }[@(deviceSize)]; } @@ -186,6 +319,26 @@ + (NSString *)deviceNameForVersion:(DeviceVersion)deviceVersion @(iPhone8Plus) : @"iPhone 8 Plus", @(iPhoneX) : @"iPhone X", @(iPhoneSE) : @"iPhone SE", + @(iPhoneXS) : @"iPhone XS", + @(iPhoneXR) : @"iPhone XR", + @(iPhoneXSMax) : @"iPhone XS Max", + @(iPhone11) : @"iPhone11", + @(iPhone11Pro) : @"iPhone11Pro", + @(iPhone11ProMax) : @"iPhone11ProMax", + @(iPhoneSE2) : @"iPhoneSE2", + @(iPhone12) : @"iPhone12", + @(iPhone12Pro) : @"iPhone12Pro", + @(iPhone12ProMax) : @"iPhone12ProMax", + @(iPhone12Mini) : @"iPhone12Mini", + @(iPhone13) : @"iPhone13", + @(iPhone13Pro) : @"iPhone13Pro", + @(iPhone13ProMax) : @"iPhone13ProMax", + @(iPhone13Mini) : @"iPhone13Mini", + @(iPhoneSE3) : @"iPhoneSE3", + @(iPhone14) : @"iPhone14", + @(iPhone14Plus) : @"iPhone14Plus", + @(iPhone14Pro) : @"iPhone14Pro", + @(iPhone14ProMax) : @"iPhone14ProMax", @(iPad1) : @"iPad 1", @(iPad2) : @"iPad 2", @@ -202,14 +355,29 @@ + (NSString *)deviceNameForVersion:(DeviceVersion)deviceVersion @(iPad5) : @"iPad 5", @(iPadPro10Dot5Inch) : @"iPad Pro 10.5 inch", @(iPadPro12Dot9Inch2Gen): @"iPad Pro 12.9 inch", + @(iPadPro12Dot9Inch4Gen): @"iPad Pro 12.9 inch 4", + @(iPad6) : @"iPad 6", + @(iPadAir3) : @"iPadAir3", + @(iPad7) : @"iPad 7", + @(iPadPro11Inch) : @"iPadPro11Inch", + @(iPadMini5) : @"iPadMini5", + @(iPadPro11Inch2Gen) : @"iPadpro11Inch2Gen", + @(iPad8) : @"iPad8", + @(iPadAir4) : @"iPadAir4", + @(iPadMini6) : @"iPadMini6", + @(iPadPro12Dot9Inch5Gen): @"iPadPro12Dot9Inch5Gen", + @(iPadPro11Inch3Gen) : @"iPadPro11Inch3Gen", + @(iPad9) : @"iPad9", + @(iPadAir5) : @"iPadAir5", @(iPodTouch1Gen) : @"iPod Touch 1st Gen", @(iPodTouch2Gen) : @"iPod Touch 2nd Gen", @(iPodTouch3Gen) : @"iPod Touch 3rd Gen", @(iPodTouch4Gen) : @"iPod Touch 4th Gen", @(iPodTouch5Gen) : @"iPod Touch 5th Gen", - @(iPodTouch6Gen) : @"iPod Touch 6th Gen", - + @(iPodTouch6Gen) : @"iPod Touch 6th Gen", + @(iPodTouch7Gen) : @"iPod Touch 7th Gen", + @(Simulator) : @"Simulator", @(UnknownDevice) : @"Unknown Device" }[@(deviceVersion)]; diff --git a/SDVersion/SDtvOSVersion/SDtvOSVersion.h b/SDVersion/SDtvOSVersion/SDtvOSVersion.h index b2a1bbc..adebf98 100755 --- a/SDVersion/SDtvOSVersion/SDtvOSVersion.h +++ b/SDVersion/SDtvOSVersion/SDtvOSVersion.h @@ -8,9 +8,10 @@ #import typedef NS_ENUM(NSInteger, DeviceVersion) { - AppleTV4 = 1, - AppleTV4K = 2, - Simulator = 0 + Simulator, + AppleTV4, + AppleTV4K, + AppleTV4K2Gen }; @interface SDtvOSVersion : NSObject diff --git a/SDVersion/SDtvOSVersion/SDtvOSVersion.m b/SDVersion/SDtvOSVersion/SDtvOSVersion.m index f3c4961..9b6db15 100755 --- a/SDVersion/SDtvOSVersion/SDtvOSVersion.m +++ b/SDVersion/SDtvOSVersion/SDtvOSVersion.m @@ -21,6 +21,7 @@ + (NSDictionary*)deviceNamesByCode deviceNamesByCode = @{ @"AppleTV5,3" : @(AppleTV4), @"AppleTV6,2" : @(AppleTV4K), + @"AppleTV11,1" : @(AppleTV4K2Gen) }; }); @@ -29,9 +30,18 @@ + (NSDictionary*)deviceNamesByCode + (DeviceVersion)deviceVersion { - struct utsname systemInfo; - uname(&systemInfo); - NSString *code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; + NSString *code = nil; + +#if TARGET_OS_SIMULATOR + code = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; +#endif // TARGET_OS_SIMULATOR + + if (code == nil) { + struct utsname systemInfo; + uname(&systemInfo); + code = [NSString stringWithCString:systemInfo.machine + encoding:NSUTF8StringEncoding]; + } DeviceVersion version = (DeviceVersion)[[self.deviceNamesByCode objectForKey:code] integerValue]; @@ -43,6 +53,7 @@ + (NSString *)deviceVersionName:(DeviceVersion)deviceVersion return @{ @(AppleTV4) : @"Apple TV (4th Generation)", @(AppleTV4K) : @"Apple TV 4K", + @(AppleTV4K2Gen) : @"Apple TV 4K(2nd Generation)", @(Simulator) : @"Simulator" }[@(deviceVersion)]; } diff --git a/SDVersion/SDwatchOSVersion/SDwatchOSVersion.h b/SDVersion/SDwatchOSVersion/SDwatchOSVersion.h index 1cbd6e2..0834fa0 100644 --- a/SDVersion/SDwatchOSVersion/SDwatchOSVersion.h +++ b/SDVersion/SDwatchOSVersion/SDwatchOSVersion.h @@ -9,21 +9,41 @@ typedef NS_ENUM(NSInteger, DeviceVersion) { AppleWatch38mm = 1, - AppleWatch42mm = 2, - AppleWatch38mmSeries1 = 3, - AppleWatch42mmSeries1 = 4, - AppleWatch38mmSeries2 = 5, - AppleWatch42mmSeries2 = 6, - AppleWatch38mmSeries3 = 7, - AppleWatch42mmSeries3 = 8, + AppleWatch42mm , + AppleWatch38mmSeries1 , + AppleWatch42mmSeries1 , + AppleWatch38mmSeries2 , + AppleWatch42mmSeries2 , + AppleWatch38mmSeries3 , + AppleWatch42mmSeries3 , + AppleWatch40mmSeries4 , + AppleWatch44mmSeries4 , + AppleWatch40mmSeries5 , + AppleWatch44mmSeries5 , + AppleWatch40mmSE , + AppleWatch44mmSE , + AppleWatch40mmSeries6 , + AppleWatch44mmSeries6 , + AppleWatch41mmSeries7 , + AppleWatch45mmSeries7 , + AppleWatch40mmSE2 , + AppleWatch44mmSE2 , + AppleWatch41mmSeries8 , + AppleWatch45mmSeries8 , + AppleWatch49mmUltra , Simulator = 0 }; typedef NS_ENUM(NSInteger, DeviceSize) { UnknownSize = 0, - Screen38mm = 1, - Screen42mm = 2 + Screen38mm, + Screen40mm, + Screen41mm, + Screen42mm, + Screen44mm, + Screen45mm, + Screen49mm, }; @interface SDwatchOSVersion : NSObject diff --git a/SDVersion/SDwatchOSVersion/SDwatchOSVersion.m b/SDVersion/SDwatchOSVersion/SDwatchOSVersion.m index 5af019e..2e3d250 100644 --- a/SDVersion/SDwatchOSVersion/SDwatchOSVersion.m +++ b/SDVersion/SDwatchOSVersion/SDwatchOSVersion.m @@ -26,6 +26,23 @@ + (NSDictionary*)deviceNamesByCode @"Watch3,2" : @(AppleWatch42mmSeries3), @"Watch3,3" : @(AppleWatch38mmSeries3), @"Watch3,4" : @(AppleWatch42mmSeries3), + @"Watch4,1" : @(AppleWatch40mmSeries4), + @"Watch4,2" : @(AppleWatch44mmSeries4), + @"Watch4,3" : @(AppleWatch40mmSeries4), + @"Watch4,4" : @(AppleWatch44mmSeries4), + @"Watch5,3" : @(AppleWatch40mmSeries5), + @"Watch5,4" : @(AppleWatch44mmSeries5), + @"Watch5,9" : @(AppleWatch40mmSE), + @"Watch5,12" : @(AppleWatch44mmSE), + @"Watch6,1" : @(AppleWatch40mmSeries6), + @"Watch6,2" : @(AppleWatch44mmSeries6), + @"Watch6,6" : @(AppleWatch41mmSeries7), + @"Watch6,9" : @(AppleWatch45mmSeries7), + @"Watch6,13" : @(AppleWatch40mmSE2), + @"Watch6,13" : @(AppleWatch44mmSE2), + @"Watch6,14" : @(AppleWatch41mmSeries8), + @"Watch6,15" : @(AppleWatch45mmSeries8), + @"Watch6,18" : @(AppleWatch49mmUltra), }; }); @@ -34,9 +51,18 @@ + (NSDictionary*)deviceNamesByCode + (DeviceVersion)deviceVersion { - struct utsname systemInfo; - uname(&systemInfo); - NSString *code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; + NSString *code = nil; + +#if TARGET_OS_SIMULATOR + code = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; +#endif // TARGET_OS_SIMULATOR + + if (code == nil) { + struct utsname systemInfo; + uname(&systemInfo); + code = [NSString stringWithCString:systemInfo.machine + encoding:NSUTF8StringEncoding]; + } DeviceVersion version = (DeviceVersion)[[self.deviceNamesByCode objectForKey:code] integerValue]; @@ -54,6 +80,21 @@ + (NSString *)deviceVersionName:(DeviceVersion)deviceVersion @(AppleWatch42mmSeries2) : @"Apple Watch Series 2 42mm", @(AppleWatch38mmSeries3) : @"Apple Watch Series 3 38mm", @(AppleWatch42mmSeries3) : @"Apple Watch Series 3 42mm", + @(AppleWatch40mmSeries4) : @"Apple Watch Series 4 40mm", + @(AppleWatch44mmSeries4) : @"Apple Watch Series 4 44mm", + @(AppleWatch40mmSeries5) : @"Apple Watch Series 5 40mm", + @(AppleWatch44mmSeries5) : @"Apple Watch Series 5 44mm", + @(AppleWatch40mmSE) : @"Apple Watch Series SE 40mm", + @(AppleWatch44mmSE) : @"Apple Watch Series SE 44mm", + @(AppleWatch40mmSeries6) : @"Apple Watch Series 6 40mm", + @(AppleWatch44mmSeries6) : @"Apple Watch Series 6 44mm", + @(AppleWatch41mmSeries7) : @"Apple Watch Series 7 41mm", + @(AppleWatch45mmSeries7) : @"Apple Watch Series 7 45mm", + @(AppleWatch40mmSE2) : @"Apple Watch Series SE2 40mm", + @(AppleWatch44mmSE2) : @"Apple Watch Series SE2 44mm", + @(AppleWatch41mmSeries8) : @"Apple Watch Series 8 41mm", + @(AppleWatch45mmSeries8) : @"Apple Watch Series 8 45mm", + @(AppleWatch49mmUltra) : @"Apple Watch 49mm Ultra", @(Simulator) : @"Simulator" }[@(deviceVersion)]; } @@ -62,10 +103,20 @@ + (DeviceSize)deviceSize { CGFloat screenHeight = CGRectGetHeight([WKInterfaceDevice currentDevice].screenBounds); - if (screenHeight == 195) { + if (screenHeight == 224) { + return Screen44mm; + } else if (screenHeight == 195) { return Screen42mm; + } else if(screenHeight == 197) { + return Screen40mm; } else if(screenHeight == 170) { return Screen38mm; + } else if(screenHeight == 215) { + return Screen41mm; + } else if(screenHeight == 242) { + return Screen45mm; + } else if(screenHeight == 251) { + return Screen49mm; } else { return UnknownSize; } @@ -76,7 +127,12 @@ + (NSString *)deviceSizeName:(DeviceSize)deviceSize return @{ @(UnknownSize) : @"Unknown Size", @(Screen38mm) : @"38mm", - @(Screen42mm) : @"42mm" + @(Screen40mm) : @"40mm", + @(Screen41mm) : @"41mm", + @(Screen42mm) : @"42mm", + @(Screen44mm) : @"44mm", + @(Screen45mm) : @"45mm", + @(Screen49mm) : @"49mm" }[@(deviceSize)]; } @@ -86,7 +142,7 @@ + (NSString *)deviceName uname(&systemInfo); NSString *code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; if ([code isEqualToString:@"x86_64"] || [code isEqualToString:@"i386"]) { - code = @"Simulator"; + code = [NSString stringWithFormat:@"%@ Simulator", code]; } return code;