Is there a way to determine the device running an application. I want to distinguish between iPhone
and iPod Touch
, if possible.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
You can check GBDeviceInfo on GitHub, also available via CocoaPods. It provides simple API for detecting various properties with support of all latest devices:
[GBDeviceInfo deviceDetails].family == GBDeviceFamilyiPhone;
[GBDeviceInfo deviceDetails].model == GBDeviceModeliPhone6.
For more see Readme.
I took it a bit further and converted the big "isEqualToString" block into a classification of bit masks for the device type, the generation, and that other qualifier after the comma (I'm calling it the sub generation). It is wrapped in a class with a singleton call SGPlatform which avoids a lot of repetitive string operations. Code is available https://github.com/danloughney/spookyGroup
The class lets you do things like this:
and
The classification of the devices is in the platformBits method. That method should be very familiar to the readers of this thread. I have classified the devices by their type and generation because I'm mostly interested in the overall performance, but the source can be tweaked to provide any classification that you are interested in, retina screen, networking capabilities, etc..
Please feel free to use this class (gist @ github)
UPDATE (01/14/11)
Obviously, this code is a bit out of date by now, but it can certainly be updated using the code on this thread provided by
Brian Robbins
which includes similar code with updated models. Thanks for the support on this thread.There's a pretty mature library (by me) for that called SDVersion. You can check for running device's model, screen size and many other parameters. It also supports OSX.
Example:
For simple comparison I always like macro:
It's simple and easy to use.
I'd like to add that to retrieve the front and enclosure color of the device there's a private API:
I've blogged about this and provide a sample app:
http://www.futuretap.com/blog/device-colors/