Skip to content

Instantly share code, notes, and snippets.

@romyilano
Created April 15, 2013 06:12
Show Gist options
  • Select an option

  • Save romyilano/5386047 to your computer and use it in GitHub Desktop.

Select an option

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.
//
// 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