Question

How can I tell if the application is running on iPhone 4 or iPhone 3GS or an iPad?

I want to determine if which hardware I'm using and then provide additional functionality if it's an iPhone 4 (such as using the video light or gyro-sensor).

Any help would greatly be appreciated.

Thanks

PS: I'm looking to determine this programmatically and not determine if based on physical appearance.

Was it helpful?

Solution

RE: sample code to detect if a flash is available

   for (AVCaptureDevice *cameraDevice in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
        if ([cameraDevice hasFlash]) {
            NSLog(@" Yay! A flash!"):
        }
    }

But seriously, dude, Vladimir gave you the class name and the method name. If you had opened the documentation, you'd have had figured it out in a jiffy - certainly quicker than waiting on someone to paste you five lines of code.

OTHER TIPS

Rather then determining device model you should find and use APIs checking if desired functionality is available. For example hasFlash property of AVCaptureDevice for flash and gyroAvailable property of CMMotionManager for gyroscope.

If your app can run on iOS prior to iOS4 you should also perform extra check if listed above properties and classes are available in run-time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top