iPad 2 detection

Martin picture Martin · Mar 17, 2011 · Viewed 12.2k times · Source

Since I don't have iPad 2, I need to know what it returns when calling [[UIDevice currentDevice] model]. I thought it returns just "iPad" but it seems I'm wrong.

Can somebody let me know?

Thanks

Answer

Marcelo Cantos picture Marcelo Cantos · Apr 26, 2011

Check for an iPad with a camera.

BOOL isIPad2 = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
                [UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]);

Note that it is generally better to detect specific features rather than make blanket assumptions based on model/version detection. For instance, if you need a camera, then test for the camera explicitly; if you need to tweak the UI quality based on the amount of RAM available, test for physical RAM; etc. Also note a comment I wrote that highlights the dangers of using model detection.