UIDevice Class for Noobs to get UDID, Model, Device Name and Battery Level

The UIDevice class provides all detail in the current device when someone use this apps. You can obtain information about the device such as assigned Device Name, Device Model, iOS Version and Battery Level.




Let's Start:

Create new project in Single View Application.


Open the ViewController.m file and put a code like this in method viewDidLoad() for call UDID:

- (void)viewDidLoad
{ [super viewDidLoad];
NSString *udid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

NSLog(@"UDID is %@",udid);
// Do any additional setup after loading the view, typically from a nib.}

"Run" you project on iPhone Simulator and see the detail in the Console, UDID of iPhone Simulator will display the information.


The code for get information of Device Name (The name of you phone when connect with iTunes).

- (void)viewDidLoad
{ [super viewDidLoad];
NSString *udid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSString *DeviceName =[[UIDevice currentDevice] name];

NSLog(@"UDID is %@",udid);
NSLog(@"Device Name is %@",DeviceName);
// Do any additional setup after loading the view, typically from a nib.}
Run your project:


You can use the UIDevice instance to obtain information and notifications about changes to the battery’s charge state, device model and iOS version put the code like this:

- (void)viewDidLoad
{ [super viewDidLoad];
NSString *udid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSString *DeviceName =[[UIDevice currentDevice] name];
NSString *model =[[UIDevice currentDevice] model];
NSString *systemVersion =[[UIDevice currentDevice] systemVersion];
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
float batteryLevel = [[UIDevice currentDevice] batteryLevel];


NSLog(@"UDID is %@",udid);
NSLog(@"Device Name is %@",DeviceName);
NSLog(@"Model is %@",model);
NSLog(@"OS version%@",systemVersion);
NSLog(@"Battery Level: %f",batteryLevel);
// Do any additional setup after loading the view, typically from a nib.}


Run again:



Have fun!

Comments