Cocoa Dev
Cocoa Dev

Reputation: 9541

Determine the hardware for iPhone

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.

Upvotes: 1

Views: 915

Answers (2)

Svetoslav
Svetoslav

Reputation: 155

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.

Upvotes: 5

Vladimir
Vladimir

Reputation: 170809

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.

Upvotes: 6

Related Questions