ekhoo / device Goto Github PK
View Code? Open in Web Editor NEWLight weight tool for detecting the current device and screen size written in swift.
License: MIT License
Light weight tool for detecting the current device and screen size written in swift.
License: MIT License
😄
Apple releases new devices each year(sometimes some season), and it force this library to release new version whenever new size of device came out.
When it comes to device size, most of people expect this lib to do its best effort, I think.
So I'd like to propose Device.size
to return the nearest size as long as they know in the released version.
Once my proposal accepted, Device.size
would be implemented like below.
static public func size() -> Size {
/ * bra bra bra * /
switch screenHeight {
case 0...480:
return .screen3_5Inch
case 481...568:
return .screen4Inch
case 569...667:
return UIScreen.main.scale == 3.0 ? .screen5_5Inch : .screen4_7Inch
case 668...736:
return .screen5_5Inch
/* and so on... */
What do you people think about this?
Hey,
I think it would be really useful (for me at least) if we could have some extra helper functions that simply return either true or false. A function that returns true if the current device is either a 4inch or below etc.
Of course I can just write them myself in my project, but thought it might be useful if they were part of this lib. What do you think?
Pretty much the title. Trying to migrate from Cocoapods -> SPM, looks like all we need is the manifest file.
Added a fue lines of code to support the iPad mini 5:
In version.swift
added:
case iPadMini5
In device.swift
added:
case "iPad11,1", "iPad11,2": return .iPadMini5
I'm sorry its not the arruino. It's the Orange pi 3 that I am have issues with. When I turn it on it goes into a white screen even though the background is still working. I'm trying to see how I can take the white screen out or off. Or is there any way to reset the hardware.
iPhone XS Max size going to default case.
Thanks for your library, can you update the newer devices ?
I tried
if Device.version == .iPhoneX
if Device.type == .iPhoneX
both failed on simulator.
this worked.
if UIDevice.isIphoneX
extension UIDevice {
static var isIphoneX: Bool {
var modelIdentifier = ""
if isSimulator {
modelIdentifier = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? ""
} else {
var size = 0
sysctlbyname("hw.machine", nil, &size, nil, 0)
var machine = [CChar](repeating: 0, count: size)
sysctlbyname("hw.machine", &machine, &size, nil, 0)
modelIdentifier = String(cString: machine)
}
return modelIdentifier == "iPhone10,3" || modelIdentifier == "iPhone10,6"
}
static var isSimulator: Bool {
return TARGET_OS_SIMULATOR != 0
}
}
Hello, At WWDC23 Apple announced that apps and SDKs that make use of certain "required reason" APIs etc will need to provide a privacy manifest.
Does Device need to include this manifest?
Is this update on the roadmap for the team? I appreciate that enforcement won't happen until Spring 2024 but I wanted to make contact so that we can plan our own app releases to take this into account.
Here’s some useful references:
https://developer.apple.com/videos/play/wwdc2023/10060/
Thanks
Hi,
Any plan to support watch OS ?
I may be able to make a PR if you are open for it.
Lucas.
PR here: #74
The original SDVersion library is protected under MIT License.
I kindly ask you to change the logo and the description as you do not posses permission to use them on your behalf.
Regards,
Sebastian
Hey there,
Thanks for this library. Noticed something wrong with it, line 71: https://github.com/Ekhoo/Device/blob/master/Source/Device.swift#L71
I think that should be returning the Size.Screen4Inch enum.
Can you add Carthage compatibility?
Thanks
its 6S Plus, not 6 Plus S
Currently, the podspec specify the deployment target to iOS 8.0.
For other Cocoapods libraries, if you have Device
as a dependency pod, your library will not lint correctly your podspec using Xcode 14.3 and up. Please refer to this issue on Cocoapods.
So far there is no way to specify custom deployment targets for dependencies with the Podspec syntax, so this should be resolved by each pod podspec.
This is not a problem if you install the dependency via SPM or directly into your project via cocoapods
Hi!
Given the number of issues open and the absence of support for the last iOS devices (iPhone 13), I wanted to ask if this project is still being maintained?
Hi @Ekhoo, thanks for this library, I like it and use it often.
Sometimes model identifier is used in a "raw" value (i.e. "iPhone9,4"), for instance when sending client device information to a backend or similar, but in current version of Device
this info is hidden behind static fileprivate func getVersionCode() -> String
. Would you mind making that public?
Also, is there a particular reason for all of these version
, size
, type
to be static methods instead of static properties? To me it seems a little bit more convenient if those were just properties instead of methods... What do you think?
Cheers,
// T
Device.size() returns unknownSize for iPad 8th gen 10.2 inch
Carthage's operator ~>
means
the version equals or later than right-hand version which is compatible with that
And also, this rule from the semantic versioning. http://semver.org/
If you can follow this rule, It's better to version as 2.0.0 because 1.1.0 is just supporting Swift3 and Swift3 is not compatible with Swift2.3 (1.0.3 or earlier).
In other word, if we wrote github "Ekhoo/Device" ~> 1.0.3
, we can't build the library without changes of our codes.
when run carthage update, the carthage complains build error:
*** Skipped building Device due to the error:
Dependency "Device" has no shared framework schemes
If you believe this to be an error, please file an issue with the maintainers at https://github.com/Ekhoo/Device/issues/new
iPhone 6 Plus uses 3x assets, everything else below it uses 2x image assets.
Hey guys, could be possible to have the compatibility with Swift 2.3?
First of all, thanks for this pod.
A lot of times I want to check if the current device is of a specific type and I think it would be easier doing
if(Device.isPad()) //instead of if (Device.type() == .iPad)
So what do you think if I create a PR with the following code?
static public func isPad() -> Bool {
return Device.type() == .iPad
}
static public func isPhone() -> Bool {
return Device.type() == .iPhone
}
static public func isPod() -> Bool {
return Device.type() == .iPod
}
iPhone 12 Mini: 5.4" with 1080×2340 pixels
iPhone 12 / 12 Pro: 6.1" with 1170×2532 pixels
iPhone 12 Pro Max: 6.7" with 1284×2778 pixels
Is there a way for this library to detect Display Zoom? It doesn't appear to do so currently.
Even though Swift 3.x and Swift 4 are interchangeable, it would be great if there were a Swift 4 version! Are there any plans for this? Thanks! 😄
When I install 3.0.3, I get this error.
[!] Unable to satisfy the following requirements:
Device (~> 3.0.3)
required by Podfile
Device (~> 3.0.3)
.I can only install it up to 3.0.2, any idea to fix this?
This framework cannot currently recognize iPad Minis
Additionally it cannot differentiate between the new Gen 2 iPad Pros. The classification information in the iPad pro section conflicts with other reports of what they should be.
The screen sizes are there for the iPhones, but not for the iPads.
how about creating variable like singleton than func size, type, version
because after once called, size, type, version never changed in same device
everytime, when use Device.size()
, Device.getVersion() ...
every time calculated
Is this project still maintained, or does a PR need to be made?
Do you have any plans to add a Privacy Manifest to this library?
Is this library not required to be supported?
Thank you very much!
@Ekhoo Started here: Sweefties@7e7f025 & Sweefties@c6da20e
wait for checks (models identifiers)..
👼
Experiencing this using Xcode 8.1 and Swift 3. After installing with cocoapods, I'm getting this build error:
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.
I remember having to do this for Swift 2.3 about a month ago, but looking at the releases for the repo I assumed that master would work just fine for swift 3 projects.
So cocoapods downloads the version 3.1.0 of the library without all the latest changes as the version specified in the podspec is 3.1.0 and not 3.1.2
case 896:
switch version() {
case .iPhoneXS_Max:
return .screen6_5Inch
default:
return .screen6_1Inch
}
should be
case 896:
switch version() {
case .iPhoneXS_Max, iPhone11Pro_Max:
return .screen6_5Inch
default:
return .screen6_1Inch
}
Hi,
I love your repo so much that I have created a YouTube video tutorial on it:
https://www.youtube.com/watch?v=cTZcOaGgD-E
Feel free to add it to the README with the following image (people click on images more often than simple links)
Keep up the good work :)
I could not find "iPhone4,2", "iPhone4,3" https://www.theiphonewiki.com/wiki/Models and other tech blogs.
Does "iPhone4,2", "iPhone4,3" exist?
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.