你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> ios檢測設備攝像頭、指南針、錄音、陀螺儀的狀態

ios檢測設備攝像頭、指南針、錄音、陀螺儀的狀態

編輯:IOS開發綜合
//檢查前後攝像頭
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
}

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved