IOS Study Notes (13th) -- get mobile phone information (UIDevice, NSBundle, NSLocale)

Source: Internet
Author: User
During app development in iOS, sometimes, for Bug Tracking or feedback, the user's device, system information, and application information need to be automatically collected. This information is convenient for developers to diagnose problems, of course, this information is non-private information of the user and can be obtained through the Development API. Which APIs can be used to obtain this information? The ios sdk provides uidevice, nsbundle, and nslocale.
Uidevice

Uidevice provides multiple attributes, class functions, and status notifications to help us fully understand the device status. From detecting battery power to locating devices and proximity sensing, uidevice provides users and devices for applications. The uidevice class can also collect various details about devices, such as models and IOS versions. Most of these attributes play a positive role in assisting development. The following code uses uidevice to obtain the mobile phone attributes.

// NSString * strName = [[UIDevice currentDevice] name]; NSLog (@ "device name: % @", strName); // e.g. "My iPhone" NSString * strId = [[UIDevice currentDevice] uniqueIdentifier]; NSLog (@ "unique identifier of a device: % @", strId); // UUID, after 5.0, NSString * strSysName = [[UIDevice currentDevice] systemName]; NSLog (@ "system name: % @", strSysName); // e.g. @ "iOS" NSString * strSysVersion = [[UIDevice currentDevice] systemVersion]; NSLog (@ "System Version: % @", strSysVersion); // e.g. @ "4.0" NSString * strModel = [[UIDevice currentDevice] model]; NSLog (@ "device mode: % @", strModel); // e.g. @ "iPhone", @ "iPod touch" NSString * strLocModel = [[UIDevice currentDevice] localizedModel]; NSLog (@ "local device mode: % @", strLocModel ); // localized version of model

Nsbundle

Bundle is a directory that contains the resources used by the program. these resources contain images, sounds, compiled code, and nib files (bundle is also called plug-in ). corresponding bundle. cocoa provides the NSBundle class. an application seems to be no different from other files. but it is actually a directory that contains nib files, compiled code, and other resources. we call this directory the main bundle of the program. This path can be used to obtain information about an application, such as the application name and version number.

// NSDictionary * dicInfo = [[NSBundle mainBundle] infoDictionary]; // CFShow (dicInfo); NSString * strAppName = [dicInfo objectForKey: @ "CFBundleDisplayName"]; NSLog (@ "App name: % @", strAppName); NSString * strAppVersion = [dicInfo objectForKey: @ "cfbundle#versionstring"]; NSLog (@ "App version: % @", strAppVersion); NSString * strAppBuild = [dicInfo objectForKey: @ "CFBundleVersion"]; NSLog (@ "App Build version: % @ ", strAppBuild );

Nslocale can be used to obtain the user's Localization information settings, such as formatting the currency type, country, language, number, date format, and providing correct geographic location display. The following code gets the current language and country code of the machine.

// Getting the User's Language NSArray * export agearray = [NSLocale preferredLanguages]; NSString * language = [Export agearray objectAtIndex: 0]; NSLog (@ "Language: % @", language); // en NSLocale * locale = [NSLocale currentLocale]; NSString * country = [locale localeIdentifier]; NSLog (@ "country: % @", country); // en_US

/**

* @ Author Zhang xingye * http://blog.csdn.net/xyz_lmn* iOS entry group: 83702688

* Android Development Group: 241395671

* My Sina Weibo:@ Zhang xingye TBOW*/Reference: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html
Https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html
Https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSLocale_Class/Reference/Reference.html
Http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-accessing-device-data-with-uidevice-and-nslocale/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.