开发者

Determine the hardware for iPhone

Ho开发者_Go百科w 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜