//檢查前後攝像頭 BOOL cameraAvailable = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];//前 BOOL frontCameraAvailable = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];//後 //檢查指南針 CoreLocation.framework <CoreLocation/CoreLocation.h> BOOL magnetometerAvailbale = [CLLocationManager headingAvailable]; //檢查聲音支持 AVFoundation.framework <AVFoundation/AVFoundation.h> AVAudioSession *audioSession = [AVAudioSession sharedInstance]; //返回一個AVAudioSession實例 BOOL audioAvailable = audioSession.inputAvailable;//bool值。獲取是否支持 //檢查錄像支持 MobileCoreServices.framework <MobileCoreServices/MobileCoreServices.h> - (BOOL)isvideoCameraAvailable { //簡單檢查所有的可用的媒體資源類型,然後檢查返回的數組,如果其中包含了kUTTypeMovie的NSString類型對象,就證明攝像頭支持錄像 UIImagePickerController *picker = [[UIImagePickerController alloc]init]; NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];//返回所支持的media的類型數組 [picker release]; if (![sourceTypes containsObject:(NSString *)kUTTypeMovie]) {//containsObject確定數組中是否包含後面的對象 return NO; } return YES; } //檢查陀螺儀可用 CoreMotion.framework <CoreMotion/CoreMotion.h> - (BOOL) isGyroscopeAvailable { #ifdef __IPHONE_4_0//4.0之後才有 CMMotionManager *motionManager = [[CMMotionManager alloc]init]; BOOL gyroscopeAvailable = motionManager.gyroAvailable; [motionManager release]; return gyroscopeAvailable; #else return NO; #endif }