Created
April 15, 2013 06:12
-
-
Save romyilano/5386047 to your computer and use it in GitHub Desktop.
Check if various hardware components are available. source: professional iOS augmented reality dev.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // FirstViewController.m | |
| // iOS_AR_Ch2_HardwareComparison | |
| // | |
| // Created by Kyle Roche on 6/13/11. | |
| // Copyright 2011 Isidorey. All rights reserved. | |
| // | |
| #import "FirstViewController.h" | |
| @implementation FirstViewController | |
| // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. | |
| - (void)viewDidLoad | |
| { | |
| // check for camera | |
| BOOL cameraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; | |
| // check for front facing camera | |
| BOOL frontCameraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerCameraDeviceFront]; | |
| if (cameraAvailable) { | |
| UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera" | |
| message:@"Camera Available" | |
| delegate:self | |
| cancelButtonTitle:@"OK" | |
| otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| [alert release]; | |
| } else { | |
| UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera" | |
| message:@"Camera NOT Available" | |
| delegate:self | |
| cancelButtonTitle:@"OK" | |
| otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| [alert release]; | |
| } | |
| if (frontCameraAvailable) { | |
| UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera" | |
| message:@"Front Camera Available" | |
| delegate:self | |
| cancelButtonTitle:@"OK" | |
| otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| [alert release]; | |
| } else { | |
| UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera" | |
| message:@"Front Camera NOT Available" | |
| delegate:self | |
| cancelButtonTitle:@"OK" | |
| otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| [alert release]; | |
| } | |
| // checking for video support | |
| if ([self isVideoCameraAvailable]) { | |
| UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Video" | |
| message:@"Video Available" | |
| delegate:self | |
| cancelButtonTitle:@"OK" | |
| otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| [alert release]; | |
| } else { | |
| UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Video" | |
| message:@"Video NOT Available" | |
| delegate:self | |
| cancelButtonTitle:@"OK" | |
| otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| [alert release]; | |
| } | |
| BOOL magnetometerAvailable = [CLLocationManager headingAvailable]; | |
| if (magnetometerAvailable) { | |
| UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Magnetometer" | |
| message:@"Magnetometer Available" | |
| delegate:self | |
| cancelButtonTitle:@"OK" | |
| otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| [alert release]; | |
| } else { | |
| UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Magnetometer" | |
| message:@"Magnetometer NOT Available" | |
| delegate:self | |
| cancelButtonTitle:@"OK" | |
| otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| [alert release]; | |
| } | |
| if ([self isGyroscopeAvailable]) { | |
| UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Gyroscope" | |
| message:@"Gyroscope Available" | |
| delegate:self | |
| cancelButtonTitle:@"OK" | |
| otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| [alert release]; | |
| } else { | |
| UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Gyroscope" | |
| message:@"Gyroscope NOT Available" | |
| delegate:self | |
| cancelButtonTitle:@"OK" | |
| otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| [alert release]; | |
| } | |
| [super viewDidLoad]; | |
| } | |
| - (BOOL) isVideoCameraAvailable | |
| { | |
| UIImagePickerController *picker = [[UIImagePickerController alloc] init]; | |
| NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType]; | |
| [picker release]; | |
| if (![sourceTypes containsObject:(NSString *)kUTTypeMovie]){ | |
| return NO; | |
| } | |
| return YES; | |
| } | |
| - (BOOL) isGyroscopeAvailable | |
| { | |
| #ifdef __IPHONE_4_0 | |
| CMMotionManager *motionManager = [[CMMotionManager alloc] init]; | |
| BOOL gyroscopeAvailable = motionManager.gyroAvailable; | |
| [motionManager release]; | |
| return gyroscopeAvailable; | |
| #else | |
| return NO; | |
| #endif | |
| } | |
| - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | |
| { | |
| // Return YES for supported orientations | |
| return (interfaceOrientation == UIInterfaceOrientationPortrait); | |
| } | |
| - (void)didReceiveMemoryWarning | |
| { | |
| // Releases the view if it doesn't have a superview. | |
| [super didReceiveMemoryWarning]; | |
| // Release any cached data, images, etc. that aren't in use. | |
| } | |
| - (void)viewDidUnload | |
| { | |
| [super viewDidUnload]; | |
| // Release any retained subviews of the main view. | |
| // e.g. self.myOutlet = nil; | |
| } | |
| - (void)dealloc | |
| { | |
| [super dealloc]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment