views:

260

answers:

2

Hello

I was wondering how to only let iPhone 4 use my app which uses the front camera. Can I do a + (BOOL)isCameraDeviceAvailable:(UIImagePickerControllerCameraDevice) and how do I implement it so that it gives some sort of error if it returns no

or do I have to a NSString *DeviceType etc..

if iPhone 4 ... do nothing

if else ... Display alert?

How do I implement that in my app?

TIA!

+3  A: 

Put this in your app delegate's applicationDidFinishLaunching method:

if (![UIImagePickerViewController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront])
{
     [[[[UIAlertView alloc] initWithTitle: @"No Front Camera" 
                                  message: @"This app requires a front camera." 
                                 delegate: self 
                        cancelButtonTitle: @"Ok" 
                        otherButtonTitles: nil] autorelease] show];
}
sdolan
Thank you! I will try it!
Sum
Okay. Sorry to be a total noob, but where do I declare it?
Sum
Geez. The code for the UIImagePickerController was working. Ahh! Can you guide me through what and where I need to declare it I know you need to include this in somewhere. @property(nonatomic) UIImagePickerControllerSourceType sourceType
Sum
See my code above... the `UIImagePickerControllerSourceType` is passed into the `+isCameraDeviceAvailable` method. The You should have a `applicationDidFinishLaunching` in your app delegate. This question may help: http://stackoverflow.com/questions/245390/nsapplication-and-applicationdidfinishlaunching
sdolan
Yeah. I know about the app delegate but I should still need to tell it to synthesize it right. Its giving me a UIImagePickerViewController Is undeclared. Anyway this was working. I should just start over with the app and repeat what I did. I got it to work based on my specifications. Now it got removed in an iAD preperation. :( Oh well Thanks!
Sum
Though the code looks spot on. Thanks for telling me how to do it!
Sum
+5  A: 

You could add front-facing-camera to UIRequiredDeviceCapabilities in your Info.plist. That way the app won't run without front camera and your users won't be able to download it from the App Store without an iPhone 4.

ksoderstrom
Ah! That works too! I assume apple will allow it that way too!
Sum