zoukankan      html  css  js  c++  java
  • 检查设备摄像头、指南针、录像、陀螺仪的状态

    //检查前后摄像头

    - (void)cameraBtnAction:(id)sender
    {
        BOOL cameraAvailable = [UIImagePickerController isCameraDeviceAvailable:
                                                UIImagePickerControllerCameraDeviceRear];//前
        BOOL frontCameraAvailable = [UIImagePickerController isCameraDeviceAvailable:
                                                        UIImagePickerControllerCameraDeviceFront];//后
    }
     
    //检查指南针 CoreLocation.framework  <CoreLocation/CoreLocation.h>
    - (void)magnetometerBtnAction:(id)sender
    {
        BOOL magnetometerAvailbale = [CLLocationManager headingAvailable];
    }
     
    //检查声音支持 AVFoundation.framework <AVFoundation/AVFoundation.h>
    - (bool)audioBtnAction:(id)sender
    {
        //返回一个AVAudioSession实例   
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        BOOL audioAvailable = audioSession.inputAvailable;//bool值。获取是否支持
    }
     
    //检查录像支持 MobileCoreServices.framework <MobileCoreServices/MobileCoreServices.h>
    - (BOOL)isvideoCameraAvailable
    {
        //简单检查所有的可用的媒体资源类型,然后检查返回的数组,
        //如果其中包含了kUTTypeMovie的NSString类型对象,就证明摄像头支持录像
        UIImagePickerController *picker = [[UIImagePickerController alloc]init];
        //返回所支持的media的类型数组
        NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
        [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
    }
  • 相关阅读:
    继承---原型式继承
    CSS中可继承的属性
    函数定义相关
    现代密码学(对称密码——第一部分)
    数据结构练习题(1)
    数据结构与算法(线性表)
    数据结构与算法(绪论)
    大英四期中单词复习
    计算机组成原理_verilog学习_实验二答案(原创)
    现代密码学——第2章古典密码学
  • 原文地址:https://www.cnblogs.com/daguo/p/3197855.html
Copyright © 2011-2022 走看看