sebyddd / sdversion Goto Github PK
View Code? Open in Web Editor NEW:iphone: Lightweight Cocoa library for detecting the running device's model and screen size.
License: MIT License
:iphone: Lightweight Cocoa library for detecting the running device's model and screen size.
License: MIT License
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.
on xcode 6.0.1 versions simulator i am not able to detect iPhone6 / iPhone6 Plus by device size. can you please check once?
on ios 8 returning UnknownSize when the orientation is UIDeviceOrientationPortraitUpsideDown.
if (orientation == UIDeviceOrientationPortrait)
screenHeight = [[UIScreen mainScreen] bounds].size.height;
else if((orientation == UIDeviceOrientationLandscapeRight) || (orientation == UIInterfaceOrientationLandscapeLeft))
screenHeight = [[UIScreen mainScreen] bounds].size.width;
UIDeviceOrientationPortraitUpsideDown is missing on the if.
I do
if SDiOSVersion.deviceVersion() == .iPadPro {
} else {
}
else statement is executed on iPad pro simulator. How are you suppose to check device is .iPadPro on simulator? I would use screenSize but that isn't an option.
Just think "iPhone 6 Plus" is more readable than "iPhone 7,1".
Hello @sebyddd
This issue is closed once in #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
}
Hi, @sebyddd,
I found a problem, when I use SDVersion v3.0.1 via CocoaPods, it's missing some code like the following in SDiOSVersion.h. My CocoaPods version is 1.0.0.
#define stringFromDeviceVersion(v) [@{@(3):@"iPhone 4", @(4):@"iPhone 4S", @(5):@"iPhone 5", @(6):@"iPhone 5C", @(7):@"iPhone 5S", @(8):@"iPhone 6", @(9): @"iPhone 6 Plus", @(10):@"iPhone 6S", @(11): @"iPhone 6S Plus", @(12):@"iPad 1", @(13):@"iPad 2", @(14):@"iPad Mini", @(15):@"iPad 3", @(16):@"iPad 4", @(17):@"iPad Air", @(18):@"iPad Mini 2", @(19):@"iPad Air 2", @(20):@"iPad Mini 3", @(21):@"iPad Mini 4", @(22):@"iPad Pro", @(23):@"iPod Touch 1st Gen", @(24):@"iPod Touch 2nd Gen", @(25):@"iPod Touch 3rd Gen", @(26):@"iPod Touch 4th Gen", @(27):@"iPod Touch 5th Gen", @(28):@"iPod Touch 6th Gen", @(0):@"Simulator"} objectForKey:[NSNumber numberWithInteger:v]]
#define stringFromDeviceSize(v) [@{@(0):@"Unknown Size", @(1):@"3.5 inch", @(2):@"4 inch", @(3):@"4.7 inch", @(4):@"5.5 inch"} objectForKey:[NSNumber numberWithInteger:v]]
I don't know why, hope to help me, thank you!
Hello,
Can you update to support also detection for iPod Touch Devices?
Thank you
George Gerardis
There's no reason why DeviceSize
wouldn't have the iPad sizes too (9.7 and 12.9). If not, then it should be named iPhoneDeviceSize
.
My iPhone is 6plus but it detects is screen 4.7 inch.
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;
}
if ([self resolutionSize] == Screen4inch && [UIScreen mainScreen].nativeScale > 2)
will let it crash in iOS7 (iphone 5/5s Screen4inch), nativeScale can not support iOS7
iPhone 7
WATCH 2
…
I can easily get the deviceVersion, but not the name. XCode 7 gives me DeviceVersionNames does not confirm the sequenceType
now:MIT License link is http://http//opensource.org/licenses/mit-license.php.
a "http//" should be removed.
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
Not working your code for iPhone6/iPhone 6 plus resolution in XCode 6.0.1 simulators.
There is no "deviceName" function, as per the documentation.
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' */
Hi, @sebyddd
After I upgrade my Xcode to 7.3, I see this new error which was fine on Xcode 7.2.1.
When I try to use DeviceSize enum, it gives me build error.
....
let screen47Value = SDiOSVersion.DeviceSize.Screen4Dot7inch.rawValue)
-> Type of 'SDiOSVersion' has no member 'DeviceSize'
....
Do you have any workaround for this issue?
Thanks.
For universal apps it's useful.
Is there any way to detect the Apple Watch Series 3?
Thanks.
may be you can include this one too (with a license credit of course :) )
http://stackoverflow.com/a/5337804/140220
Please push your .podspec to cocoapods. Current version is 4.2.1
not the 4.3
.
Hello,
can you please update your podspec file? I just downloaded the source code using cocoapods, and it has a different version from the one on GitHub.
Thanks
@(iPhone8) : @"iPhone 8",
@(iPhoneX) : @"iPhone X",
@(iPhoneSE) : @"iPhone SE",
Should add iPhone8Plus to deviceNameForVersion
@(iPhone8Plus) : @"iPhone 8 Plus",
Hi,
Want to ask, can we have this fantastic Tool in swift 3?
It will be nice, if you have time to prepare a swift version of SDiPhoneVersion
Thanks in advance
George Gerardis
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!!
For iPhone 6Plus it is 7,1 and iPhone 6 it is 7,2
BUT for iPhone 6SPlus it is 8,2 and iPhone 6S it is 8,1.
I tested this out on my 6 and 6S to validate. Apple slightly tweaked their naming. Hope this helps you fix your code.
CHANGE FROM:
@"iPhone8,2" :[NSNumber numberWithInteger:iPhone6S],
@"iPhone8,1" :[NSNumber numberWithInteger:iPhone6SPlus],
TO:
@"iPhone8,1" :[NSNumber numberWithInteger:iPhone6S],
@"iPhone8,2" :[NSNumber numberWithInteger:iPhone6SPlus],
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?
We have iPhone 8, iPhone 8 Plus and iPhone X released. Do we have deviceNamesByCode for these new devices?
The page on this Stack Overflow post lists the subsets of devices pretty well: http://stackoverflow.com/a/19584526/2101268
Because I enjoy thoroughness, It'd be neat to see all of them listed in the device version enumerator! :)
Hi,
I use cocoapods to import this library and use use_frameworks! in my Podfile
I'm not able to do
In my other project, I don't use use_frameworks! and I can import SDVersion in my bridging header.
Hi,
Why we can not find screen size for iPad?
Can you fix it please?
Thanks very much
George Gerardis
Hi, I need to check if deviceSize is equals to 3.5" for iPhone4 but the constant not exist.
Hello Sebastian,
Do u have any plan to support this new model?
http://www.apple.com/ipad-9.7/
Thanks
Hi there. Great project!
I have a question: How can I test or run iOS device specific code on a Simulator, if SDiOSVersion.deviceVersion()
returns "Simulator" instead of "iPhone 7"?
Thanks for sharing this, I have used it in all my apps.
All along, I have a question. Since you named this library SDiOSVersion
, I think that you should support all screen size, I don't understand why there is no iPad and Watch's screen size.
FYI: http://iosres.com/
My project runs in Xcode6.1 , I import the 'SDiPhoneVersion' to my project . When complie my project , I get an error with [SDiPhoneVersion deviceSize]
method call:
Cannot initialize return object of type 'DeviceSize' with an rvalue of type 'int'
the method's return value can not be0
.
So in the defination of DeviceSize
enum , I add a new enum value named Unknowninch = 0
:
typedef NS_ENUM(NSInteger, DeviceSize){
Unknowninch = 0 ,
iPhone35inch = 1,
iPhone4inch = 2,
iPhone47inch = 3,
iPhone55inch = 4
};
and in the deviceSize
method call I change return 0
to return Unknowninch
. With these my project run ok.
A quick note for newcomers: you may have trouble with:
pod "SDVersion"
but you might have better luck with:
pod 'SDVersion'
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.
That would be great to have only one library which handle both platform directly.
I don't think that would be too much work, maybe juste the project name won't fit...
What do you think? I can work on a PR if you are ok with that.
I found iPhone5 and iPhone 5C are the same DeviceVersion NSInteger.
Your code:
typedef NS_ENUM(NSInteger, DeviceVersion){
iPhone4 = 3,
iPhone4S = 4,
iPhone5 = 5,
iPhone5C = 5,
iPhone5S = 6,
iPhone6 = 7,
iPhone6Plus = 8,
How can my app know user's device is iPhone 5C?
It would be very helpful if I could target iPad screen size and not just iPhone.
The latest 4.2.1 tag is added without the latest code to support new iPhones. Please anybody help to add a new tag with the latest work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.