Skip to content

Commit 3309726

Browse files
committedSep 11, 2010
Added UIDeviceSample
1 parent 0558fe5 commit 3309726

10 files changed

+1594
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// RootViewController.h
3+
// UIDeviceSample
4+
//
5+
// Created by Hiroshi Hashiguchi on 10/09/12.
6+
// Copyright Hiroshi Hashiguchi 2010. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface RootViewController : UITableViewController {
12+
13+
NSArray* tasks;
14+
NSArray* properties;
15+
}
16+
17+
@end
+219
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
//
2+
// RootViewController.m
3+
// UIDeviceSample
4+
//
5+
// Created by Hiroshi Hashiguchi on 10/09/12.
6+
// Copyright Hiroshi Hashiguchi 2010. All rights reserved.
7+
//
8+
9+
#import "RootViewController.h"
10+
11+
12+
@implementation RootViewController
13+
14+
15+
#pragma mark -
16+
#pragma mark View lifecycle
17+
18+
- (void)viewDidLoad {
19+
[super viewDidLoad];
20+
self.title = @"UIDevice Properties";
21+
22+
UIDevice* device = [UIDevice currentDevice];
23+
device.batteryMonitoringEnabled = YES;
24+
25+
tasks = [[NSArray alloc] initWithObjects:
26+
@"Determining the Available Features",
27+
@"Identifying the Device and Operating System",
28+
@"Getting the Device Orientation",
29+
@"Getting the Device Battery State",
30+
@"Using the Proximity Sensor",
31+
nil
32+
];
33+
34+
properties = [[NSArray alloc] initWithObjects:
35+
[NSArray arrayWithObjects:
36+
@"multitaskingSupported",
37+
nil],
38+
39+
[NSArray arrayWithObjects:
40+
@"uniqueIdentifier",
41+
@"name",
42+
@"systemName",
43+
@"systemVersion",
44+
@"model",
45+
@"localizedModel",
46+
@"userInterfaceIdiom",
47+
nil],
48+
49+
[NSArray arrayWithObjects:
50+
@"orientation",
51+
@"isGeneratingDeviceOrientationNotifications",
52+
nil],
53+
54+
[NSArray arrayWithObjects:
55+
@"batteryLevel",
56+
@"batteryMonitoringEnabled",
57+
@"batteryState",
58+
nil],
59+
60+
[NSArray arrayWithObjects:
61+
@"proximityMonitoringEnabled",
62+
@"proximityState",
63+
nil],
64+
65+
nil];
66+
67+
}
68+
69+
/*
70+
- (void)viewWillAppear:(BOOL)animated {
71+
[super viewWillAppear:animated];
72+
}
73+
*/
74+
/*
75+
- (void)viewDidAppear:(BOOL)animated {
76+
[super viewDidAppear:animated];
77+
}
78+
*/
79+
/*
80+
- (void)viewWillDisappear:(BOOL)animated {
81+
[super viewWillDisappear:animated];
82+
}
83+
*/
84+
/*
85+
- (void)viewDidDisappear:(BOOL)animated {
86+
[super viewDidDisappear:animated];
87+
}
88+
*/
89+
90+
/*
91+
// Override to allow orientations other than the default portrait orientation.
92+
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
93+
// Return YES for supported orientations.
94+
return (interfaceOrientation == UIInterfaceOrientationPortrait);
95+
}
96+
*/
97+
98+
99+
#pragma mark -
100+
#pragma mark Table view data source
101+
102+
// Customize the number of sections in the table view.
103+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
104+
return [tasks count];
105+
}
106+
107+
108+
// Customize the number of rows in the table view.
109+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
110+
return [[properties objectAtIndex:section] count];
111+
}
112+
113+
114+
// Customize the appearance of table view cells.
115+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
116+
117+
static NSString *CellIdentifier = @"Cell";
118+
119+
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
120+
if (cell == nil) {
121+
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
122+
cell.textLabel.adjustsFontSizeToFitWidth = YES;
123+
CGRect rect = cell.frame;
124+
cell.frame = rect;
125+
}
126+
127+
NSArray* props = [properties objectAtIndex:indexPath.section];
128+
NSString* key = [props objectAtIndex:indexPath.row];
129+
id value = [[UIDevice currentDevice] valueForKey:key];
130+
131+
cell.textLabel.text = key;
132+
cell.detailTextLabel.text = [value description];
133+
134+
return cell;
135+
}
136+
137+
138+
/*
139+
// Override to support conditional editing of the table view.
140+
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
141+
// Return NO if you do not want the specified item to be editable.
142+
return YES;
143+
}
144+
*/
145+
146+
147+
/*
148+
// Override to support editing the table view.
149+
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
150+
151+
if (editingStyle == UITableViewCellEditingStyleDelete) {
152+
// Delete the row from the data source.
153+
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
154+
}
155+
else if (editingStyle == UITableViewCellEditingStyleInsert) {
156+
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
157+
}
158+
}
159+
*/
160+
161+
162+
/*
163+
// Override to support rearranging the table view.
164+
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
165+
}
166+
*/
167+
168+
169+
/*
170+
// Override to support conditional rearranging of the table view.
171+
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
172+
// Return NO if you do not want the item to be re-orderable.
173+
return YES;
174+
}
175+
*/
176+
177+
178+
#pragma mark -
179+
#pragma mark Table view delegate
180+
181+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
182+
183+
/*
184+
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
185+
// ...
186+
// Pass the selected object to the new view controller.
187+
[self.navigationController pushViewController:detailViewController animated:YES];
188+
[detailViewController release];
189+
*/
190+
}
191+
192+
193+
#pragma mark -
194+
#pragma mark Memory management
195+
196+
- (void)didReceiveMemoryWarning {
197+
// Releases the view if it doesn't have a superview.
198+
[super didReceiveMemoryWarning];
199+
200+
// Relinquish ownership any cached data, images, etc that aren't in use.
201+
}
202+
203+
- (void)viewDidUnload {
204+
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
205+
// For example: self.myOutlet = nil;
206+
}
207+
208+
209+
- (void)dealloc {
210+
[super dealloc];
211+
}
212+
213+
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
214+
{
215+
return [tasks objectAtIndex:section];
216+
}
217+
218+
@end
219+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// UIDeviceSampleAppDelegate.h
3+
// UIDeviceSample
4+
//
5+
// Created by Hiroshi Hashiguchi on 10/09/12.
6+
// Copyright Hiroshi Hashiguchi 2010. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface UIDeviceSampleAppDelegate : NSObject <UIApplicationDelegate> {
12+
13+
UIWindow *window;
14+
UINavigationController *navigationController;
15+
}
16+
17+
@property (nonatomic, retain) IBOutlet UIWindow *window;
18+
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
19+
20+
@end
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//
2+
// UIDeviceSampleAppDelegate.m
3+
// UIDeviceSample
4+
//
5+
// Created by Hiroshi Hashiguchi on 10/09/12.
6+
// Copyright Hiroshi Hashiguchi 2010. All rights reserved.
7+
//
8+
9+
#import "UIDeviceSampleAppDelegate.h"
10+
#import "RootViewController.h"
11+
12+
13+
@implementation UIDeviceSampleAppDelegate
14+
15+
@synthesize window;
16+
@synthesize navigationController;
17+
18+
19+
#pragma mark -
20+
#pragma mark Application lifecycle
21+
22+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
23+
24+
// Override point for customization after application launch.
25+
26+
// Add the navigation controller's view to the window and display.
27+
[window addSubview:navigationController.view];
28+
[window makeKeyAndVisible];
29+
30+
return YES;
31+
}
32+
33+
34+
- (void)applicationWillResignActive:(UIApplication *)application {
35+
/*
36+
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
37+
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
38+
*/
39+
}
40+
41+
42+
- (void)applicationDidEnterBackground:(UIApplication *)application {
43+
/*
44+
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
45+
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
46+
*/
47+
}
48+
49+
50+
- (void)applicationWillEnterForeground:(UIApplication *)application {
51+
/*
52+
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
53+
*/
54+
}
55+
56+
57+
- (void)applicationDidBecomeActive:(UIApplication *)application {
58+
/*
59+
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
60+
*/
61+
}
62+
63+
64+
- (void)applicationWillTerminate:(UIApplication *)application {
65+
/*
66+
Called when the application is about to terminate.
67+
See also applicationDidEnterBackground:.
68+
*/
69+
}
70+
71+
72+
#pragma mark -
73+
#pragma mark Memory management
74+
75+
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
76+
/*
77+
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
78+
*/
79+
}
80+
81+
82+
- (void)dealloc {
83+
[navigationController release];
84+
[window release];
85+
[super dealloc];
86+
}
87+
88+
89+
@end
90+

0 commit comments

Comments
 (0)
Please sign in to comment.