Reputation: 14835
I'm trying to create a function that works on ALL iOS devices except the iPad 2 and the iPod Touch 5th Gen.
- (void)doSomething {
// if iPad 2 or iPod 5th Gen
if ()
{
NSLog(@"You're using an iPad 2 or iPod 5th Gen. Sorry!");
}
else
{
NSLog(@"Any other iOS device. Congrats!");
} }
Can someone post a quick sample snippet of how I would accomplish this?
Upvotes: 0
Views: 717
Reputation: 78363
If your app has a major hardware requirement (i.e., it can't really function/do anything useful if the hardware isn't present on the device), you should add an entry to the UIRequiredDeviceCapabilities
entry in your Info.plist
for your app. This will keep people who don't have the necessary hardware to use your app from purchasing it/downloading it by accident. It will also cause the App store to show a list of all the models that support your software, so people can see what they need in order to use it.
If your app has a function that requires something specific, there are generally in-framework tests you can do to see if the device has the required features/hardware. If this isn't your app's central purpose, you can then enable/disable this feature of your app based on the device's capabilities. You wouldn't want to try and query which device the user is running (except in maybe very limited circumstances), but would rather query whether the device is capable of doing what you want.
Since you mentioned an auto-focusing camera, we'll use that as an example. If your app requires this to do anything useful, you should add the UIRequiredDeviceCapabilities
key to your Info.plist
file and add the entry auto-focus-camera
to the array. This will ensure that only users who have a device with an auto-focusing camera will be able to purchase and install your app. For more information on UIKit keys for Info.plist
, including this one, see the Information Property List Key Reference.
If, on the other hand, your app is usable by any device but has a feature that requires an auto-focusing camera, you can test for it's presence using the AVFoundation
framework. You can get what you need here from the AVCaptureDevice class. For example, to check if you have access to an auto-focusing camera for video/stills:
// Check for the default camera
AVCaptureDevice* camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if( camera && [camera isFocusModeSupported:AVCaptureFocusModeAutoFocus] ) {
// this device has a default video source capable of autofocus, so enable the feature
} else {
// this device does not have the required hardware, so disable the feature
}
Upvotes: 4
Reputation: 4920
Check this:
if ([[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
//device with autofocus
}
else {
//device without autofocus
}
Upvotes: 0