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/