How to accurately determine the iDevice model?

I want to determine what the iDevice user has, and then put the device name in the UILabel . In the following code, the application only detects iPhone / iPad / iPod, I like the iPhone 4 / iPod 3G / iPad 1G ... or the exact names (iPhone 3.1 / iPod 2.0 / iPad 2.4) ...

here is my code:

 iDevice.text = [UIDevice currentDevice]. localizedModel; 

I tried this for

 iDevice.text = [UIDevice currentDevice]. model; 

but lanes he says iPhone and I like iPhone 3.1

+4
source share
1 answer

So, it looks like the method you want to use is to use the category created by Erica Sadun located at https://github.com/erica/uidevice-extension/

Before moving on to use, I will talk a bit about categories. Apple provides category documentation here http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/chapters/occategories.html

You can add methods to the class by declaring them in the interface file under the category name and defining them in the implementation file under the same name. The category name indicates that the methods are complementary to the class declared elsewhere, and not the new class. You cannot, however, use a category to add additional instance variables to a class.

Download the project from github and add these two files to your project:

 UIDevice-Hardware.h UIDevice-Hardware.m 

The methods you will use will be as follows:

 - (NSString *) platform; - (NSString *) hwmodel; - (NSUInteger) platformType; - (NSString *) platformString; 

So, you will want to import UIDevice-Hardware.h into the file in which you want to use this method. You should use the method to return the NSString value and assign the value to the label so that you do something similar to

 mylabel.text = [[UIDevice currentDevice] platformString] 

Here is another link that has a good introduction to the categories: http://mobile.tutsplus.com/tutorials/iphone/objective-c-categories/

EDIT: SCREEN SAMPLES USING THE DEVICE SIMULATOR: enter image description here Note: there is also #import "UIDevice-Hardware.h" above my @interface line.

+2
source

Source: https://habr.com/ru/post/1441364/


All Articles