码迷,mamicode.com
首页 > 其他好文 > 详细

检测设备摄像头、指南针、录音、陀螺仪状态

时间:2014-11-07 16:39:39      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:io   color   ar   os   sp   for   div   on   bs   

//检查前后摄像头

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
}

检测设备摄像头、指南针、录音、陀螺仪状态

标签:io   color   ar   os   sp   for   div   on   bs   

原文地址:http://www.cnblogs.com/daguo/p/4081352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!