Get Mobile Info

Source: Internet
Author: User

Uidevice

Uidevice provides a variety of properties, class functions, and status notifications to help us understand the state of the device in all directions. From detecting battery power to locating devices and proximity sensing, Uidevice's job is to provide users and devices with some information about the application. The Uidevice class is also capable of collecting specific details about the device, such as the model and iOS version. Most of these properties have a positive effect on development efforts. The following code simply uses Uidevice to get the phone properties.

Access to equipment-related information
NSString *strname = [[Uidevice currentdevice] name];
NSLog (@ "Device name:%@", strName);//e.g. "My IPhone"

NSString *strid = [[Uidevice currentdevice] uniqueidentifier];
NSLog (@ "Device unique ID:%@", Strid),//uuid,5.0 not available

NSString *strsysname = [[Uidevice currentdevice] systemName];
NSLog (@ "system name:%@", strsysname);//e.g. @ "IOS"

NSString *strsysversion = [[Uidevice currentdevice] systemversion];
NSLog (@ "System version number:%@", 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

CGFloat Batterylevel=[[uidevice Currentdevice] batterylevel]; Battery charge

NSBundle

A bundle is a directory that contains the resources that the program will use. These resources include like, sound, compiled code, NIB files (the user will also refer to bundles as plug-in). The corresponding BUNDLE,COCOA provides class NSBundle. An application looks no different from other files. But it's actually a directory that contains nib files, compiled code, and other resources. We call this directory the program's main bundle. This path allows you to get information about your app, such as the app name, version number, and so on.

Access to app-related information
Nsdictionary *dicinfo = [[NSBundle mainbundle] infodictionary];
Cfshow (Dicinfo);

NSString *strappname = [Dicinfo objectforkey:@ "Cfbundledisplayname"];
NSLog (@ "app app Name:%@", strappname);

NSString *strappversion = [Dicinfo objectforkey:@ "cfbundleshortversionstring"];
NSLog (@ "app version:%@", strappversion);

NSString *strappbuild = [Dicinfo objectforkey:@ "cfbundleversion"];
NSLog (@ "app build version:%@", strappbuild);

Nslocale

Nslocale can obtain the user's localization information settings, such as currency type, country, language, number, format of date format, provide correct geographical location display and so on. The following code gets the machine's current language and country code.

Getting the User ' s Language
Nsarray *languagearray = [Nslocale preferredlanguages];
NSString *language = [Languagearray objectatindex:0];
NSLog (@ "Language:%@", language);//en

Nslocale *locale = [Nslocale Currentlocale];
NSString *country = [locale localeidentifier];
NSLog (@ "Country:%@", country); en_US

Phone type: such as: IPhone 6 need to import header file: #import <sys/utsname.h>

nsstring* Phonemodel = [Self iphonetype];//method is below:

-(NSString *) Iphonetype {

struct Utsname systemInfo;

Uname (&systeminfo);

NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:nsasciistringencoding];

if ([Platform isequaltostring:@ "iphone1,1"]) return @ "IPhone 2G";

if ([Platform isequaltostring:@ "iphone1,2"]) return @ "IPhone 3G";

if ([Platform isequaltostring:@ "iphone2,1"]) return @ "IPhone 3GS";

if ([Platform isequaltostring:@ "iphone3,1"]) return @ "IPhone 4";

if ([Platform isequaltostring:@ "iphone3,2"]) return @ "IPhone 4";

if ([Platform isequaltostring:@ "iphone3,3"]) return @ "IPhone 4";

if ([Platform isequaltostring:@ "iphone4,1"]) return @ "IPhone 4S";

if ([Platform isequaltostring:@ "iphone5,1"]) return @ "IPhone 5";

if ([Platform isequaltostring:@ "iphone5,2"]) return @ "IPhone 5";

if ([Platform isequaltostring:@ "iphone5,3"]) return @ "IPhone 5c";

if ([Platform isequaltostring:@ "iphone5,4"]) return @ "IPhone 5c";

if ([Platform isequaltostring:@ "iphone6,1"]) return @ "IPhone 5s";

if ([Platform isequaltostring:@ "iphone6,2"]) return @ "IPhone 5s";

if ([Platform isequaltostring:@ "iphone7,1"]) return @ "IPhone 6 Plus";

if ([Platform isequaltostring:@ "iphone7,2"]) return @ "IPhone 6";

if ([Platform isequaltostring:@ "iphone8,1"]) return @ "IPhone 6s";

if ([Platform isequaltostring:@ "iphone8,2"]) return @ "IPhone 6s Plus";

if ([Platform isequaltostring:@ "iphone8,4"]) return @ "IPhone SE";

if ([Platform isequaltostring:@ "iphone9,1"]) return @ "IPhone 7";

if ([Platform isequaltostring:@ "iphone9,2"]) return @ "IPhone 7 Plus";

if ([Platform isequaltostring:@ "ipod1,1"]) return @ "IPod Touch 1G";

if ([Platform isequaltostring:@ "ipod2,1"]) return @ "IPod Touch 2G";

if ([Platform isequaltostring:@ "ipod3,1"]) return @ "IPod Touch 3G";

if ([Platform isequaltostring:@ "ipod4,1"]) return @ "IPod Touch 4G";

if ([Platform isequaltostring:@ "ipod5,1"]) return @ "IPod Touch 5G";

if ([Platform isequaltostring:@ "ipad1,1"]) return @ "IPad 1G";

if ([Platform isequaltostring:@ "ipad2,1"]) return @ "IPad 2";

if ([Platform isequaltostring:@ "ipad2,2"]) return @ "IPad 2";

if ([Platform isequaltostring:@ "ipad2,3"]) return @ "IPad 2";

if ([Platform isequaltostring:@ "ipad2,4"]) return @ "IPad 2";

if ([Platform isequaltostring:@ "ipad2,5"]) return @ "IPad Mini 1G";

if ([Platform isequaltostring:@ "ipad2,6"]) return @ "IPad Mini 1G";

if ([Platform isequaltostring:@ "ipad2,7"]) return @ "IPad Mini 1G";

if ([Platform isequaltostring:@ "ipad3,1"]) return @ "IPad 3";

if ([Platform isequaltostring:@ "ipad3,2"]) return @ "IPad 3";

if ([Platform isequaltostring:@ "ipad3,3"]) return @ "IPad 3";

if ([Platform isequaltostring:@ "ipad3,4"]) return @ "IPad 4";

if ([Platform isequaltostring:@ "ipad3,5"]) return @ "IPad 4";

if ([Platform isequaltostring:@ "ipad3,6"]) return @ "IPad 4";

if ([Platform isequaltostring:@ "ipad4,1"]) return @ "IPad Air";

if ([Platform isequaltostring:@ "ipad4,2"]) return @ "IPad Air";

if ([Platform isequaltostring:@ "ipad4,3"]) return @ "IPad Air";

if ([Platform isequaltostring:@ "ipad4,4"]) return @ "IPad Mini 2G";

if ([Platform isequaltostring:@ "ipad4,5"]) return @ "IPad Mini 2G";

if ([Platform isequaltostring:@ "ipad4,6"]) return @ "IPad Mini 2G";

if ([Platform isequaltostring:@ "i386"]) return @ "IPhone Simulator";

if ([Platform isequaltostring:@ "x86_64"]) return @ "IPhone Simulator";

return platform;

}

Get Mobile Info

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.