Tutorial description
Importance of device data
First, we need to clarify the question: why do we need to access device data?
If you encounter problems during use, mobile app users often send their experiences or help information to developers by email. In this case, the more detailed the email content, the larger the information, and the more specific the description of the device and system environment, the easier it is for developers to provide scientific solutions. For example, if your application needs to be connected to the Internet to run, and a user sends an email on a walking trip saying that the application cannot work properly, the conclusion becomes very clear: users cannot access the Internet through hot spots, so applications cannot be started smoothly. In addition, it is helpful to understand the IOS version, application version, and country and language settings used by users. This allows developers to quickly identify the device status of users and simplify the diagnostic process for application problems.
In addition to the bug diagnosis and problem tracking mentioned above, access information through uidevice or nslocale can also effectively improve the interface of the application (for example, automatically setting different styles of interfaces based on the user's location) appearance and actual performance.
Measure the test taker's understanding about the uidevice class.
The initial meeting with the uidevice class may come from the targeting function of the mobile device. However, in addition, uidevice provides a variety of other attributes, class functions, and notification modes to help us fully understand the device status. From detecting battery power to locating the distance between a device and the user's face, uidevice provides the application with all information about the user and the device. The uidevice class can also collect various details about devices, such as models and IOS versions. In the next tutorial, you will find that most of the attributes play a positive role in the development work.
Understanding nslocale class
Nslocale helps our applications provide the most satisfactory service results based on the user's culture and language habits. By promptly adjusting the currency type, decimal point separator, time and date format, the application can bring users more intelligent work than expected, and all of this is a humanistic factor that must be considered by successful software. In addition, nslocale can also be used for the geographical location of users. When users contact developers for help, the location is also one of the important support information.
Get device information
Let's start with getting the device models (iPhone, ipodtouch, and iPad) and IOS versions. The following code obtains the specific device model through uidevice.
- UIDevice *currentDevice = [UIDevice currentDevice];
- NSString *model = [currentDevice model];
- NSString *systemVersion = [currentDevice systemVersion];
In the first line, uidevice returns the real-time running status instance of the User device. Based on this, we can access the model, system version, and other property information to master the most critical device data.
Obtain the user language type
Next, we try to retrieve the user's language type and location settings.
- NSArray *languageArray = [NSLocale preferredLanguages];
- NSString *language = [languageArray objectAtIndex:0];
- NSLocale *locale = [NSLocale currentLocale];
- NSString *country = [locale localeIdentifier];
To obtain the user's preferred language, we need to use the prefferedlanguages class function in nslocale, which can return information in the user's current language settings. The user's current location, country, and region information is obtained through the nslocale object. In the instance, the class function localeidentifier returns a specific code containing the country/region of the user.
Obtain Application version information
Finally, let's see which version of the application the user is using.
- NSString *appVersion = [[NSBundle mainBundle]
- objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
The info. plist file in the application stores the current application version information. You only need to use the kcfbundleversionkey to access the mainbundle and return the correct application version result.
Record Device data
Next, we will summarize and record the collected device data.
- NSString *deviceSpecs =
- [NSString stringWithFormat:@"%@ - %@ - %@ - %@ - %@",
- model, systemVersion, language, country, appVersion];
-
- NSLog(@"Device Specs --> %@",deviceSpecs);
In the preceding code example, each piece of information is packaged into a string so that it can be directly displayed on the console. In an instance application, you may want this information to be displayed in the feedback email in the form of a title or text.
Summary
In the communication with application users, the more device information the developer has, the more specific the device information, the easier it is to propose a solution. Users' technical skills are uneven, so it is often difficult to accurately express their troubles. By understanding their device status in detail, developers can better help them solve problems and provide users with better services and product fun. In addition to the reasons mentioned at the beginning of the article, accessing device data can also help us better coordinate the interaction between multiple applications in the same system environment. If you have any questions or suggestions, share them with other readers in the comment bar.
Original article:
Http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-accessing-device-data-with-uidevice-and-nslocale/
- How to create an existing project after upgrading the IOS SDK
- Xcode4 ios sdk 4.3 installation experience tutorial
- Ios sdk Compatibility Guide
- Use jqm, HTML5, and IOS
SDK to build the musicbrainz Application