如何优雅地使用iOS系统相机

NSString *mediaType = AVMediaTypeVideo; // Or AVMediaTypeAudio

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];

// This status is normally not visible—the AVCaptureDevice class methods for discovering devices do not return devices the user is restricted from accessing.
if(authStatus == AVAuthorizationStatusRestricted){
    NSLog(@"Restricted");
}

// The user has explicitly denied permission for media capture.
else if(authStatus == AVAuthorizationStatusDenied){
    NSLog(@"Denied");
}

// The user has explicitly granted permission for media capture, or explicit user permission is not necessary for the media type in question.
else if(authStatus == AVAuthorizationStatusAuthorized){
    NSLog(@"Authorized");
}

// Explicit user permission is required for media capture, but the user has not yet granted or denied such permission.
else if(authStatus == AVAuthorizationStatusNotDetermined){

    [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {

        // Make sure we execute our code on the main thread so we can update the UI immediately.
        //
        // See documentation for ABAddressBookRequestAccessWithCompletion where it says
        // "The completion handler is called on an arbitrary queue."
        //
        // Though there is no similar mention for requestAccessForMediaType, it appears it does
        // the same thing.
        //
        dispatch_async(dispatch_get_main_queue(), ^{

            if(granted){
                // UI updates as needed
                NSLog(@"Granted access to %@", mediaType);
            }
            else {
                // UI updates as needed
                NSLog(@"Not granted access to %@", mediaType);
            }
        });

    }];

}

else {
    NSLog(@"Unknown authorization status");
}
时间: 2024-08-18 23:45:45

如何优雅地使用iOS系统相机的相关文章

iOS调用系统相机

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])//判断相机是否可用,模拟器不可用相机. { UIImagePickerController *imagePickerController=[[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePick

IOS开发调用系统相机和打开闪光灯

IOS开发调用系统相机和打开闪光灯      今天给大家分享一下如何调用iphone的拍照功能和打开闪光灯,有些代码我也不太理解,很多是在网上借鉴其他人的.IOS有两种的拍照和视频的方 式:1.直接使用UIImagePickerController,这个类提供了一个简单便捷的拍照与选择图片库里图片的功能.2.另一种是通过 AVFoundation.framework框架完全自定义拍照的界面和选择图片库界面.我只做了第一种,就先给大家介绍第一种做法: 一.首先调用接口前,我们需要先判断当前设备是否

iOS中 读取相册,调用系统相机 技术分享

技术内容:分别读取相册以及调取相机,将图片显示到imageView上 布局: 1.创建imageView 和 button 并为button一个关联pickerImage的事件 [objc] view plaincopy <div style="text-align: left;"><span style="font-family: Helvetica; -webkit-text-stroke-width: initial;">    sel

有关iOS系统中调用相机设备实现二维码扫描功能的注意点(3/3)

今天我们接着聊聊iOS系统实现二维码扫描的其他注意点. 大家还记得前面我们用到的输出数据的类对象吗?AVCaptureMetadataOutput,就是它!如果我们需要实现目前主流APP扫描二维码的功能,即只有当二维码进入视图中心的方框中时才进行扫描识别功能,这样做的目的主要是为了提高用户的使用体验,需要用到这个类里面的一个属性:rectOfInterest,这个属性是一个CGRect结构体类型.但和我们平时经常使用的CGRect有点不一样.以下截取了官网文档对这个属性的表述: /*! @pro

iOS开发 调用系统相机和相册

调用系统相机和相册 (iPad,iPhone)打开相机:(iPad,iPhone)//先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库      UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;  //    if (![UIImagePickerController isSourceTypeAvailab

【iOS开发之旅】iOS系统架构

iOS的系统架构分为四个层次:核心操作系统层(Core OS ).核心服务层(Core Services ).媒体层(Media )和可触摸层(Cocoa Touch ).下面是IOS系统结构图. 一.Core OS(核心操作系统层) 是用FreeBSD和Mach所改写的Darwin, 是开源.符合POSIX标准的一个Unix核心.这一层包含或者说是提供了整个iPhone OS的一些基础功能,比如:硬件驱动, 内存管理,程序管理,线程管理(POSIX),文件系统,网络(BSD Socket),以

iOS 系统权限

iOS开发中有时候有这样的需求:当用户设置不允许访问照片.麦克风和相机等系统权限的时候,这时需要直接跳转到系统的隐私界面进行设置. 判断是否开启权限 前面已经说过,我们需要在用户不允许访问的时候跳转,那么首先我们就要判断一些是否已经开启系统相机权限了. 照片权限检测 需要:#import <AssetsLibrary/AssetsLibrary.h> //导入此类和AssetsLibrary.framework框架 代码如下: int author = [ALAssetsLibrary aut

深入了解ios系统机制

1.什么叫ios? ios一般指ios(Apple公司的移动操作系统) . 苹果iOS是由苹果公司开发的移动操作系统.苹果公司最早于2007年1月9日的Macworld大会上公布这个系统,最初是设计给iPhone使用的,后来陆续套用到iPod touch.iPad以及Apple TV等产品上.iOS与苹果的Mac OS X操作系统一样,它也是以Darwin为基础的,因此同样属于类Unix的商业操作系统.原本这个系统名为iPhone OS,直到2010WWDC大会上宣布改名为iOS.最新版本为iO

iOS系统层次架构

本文转自:http://blog.csdn.net/lxl_815520/article/details/51172917 一,概述 iOS的系统架构分为四个层次:核心操作系统层(Core OS layer).核心服务层(Core Services layer).媒体层(Media layer)和可触摸层(Cocoa Touch layer).理解ios的系统构架,对我们日常开发有很大帮助.其实iOS是基于UNIX的,所以我们完全可以相信这个操作系统,要知道从系统的稳定性上来说它要比其他操作系统