强制进入手机 相册 ios_ios 调用手机相册_ios调用相机和相册

电脑杂谈  发布时间:2019-09-09 21:07:03  来源:网络整理

ios 调用相机相册_ios调用相机和相册_强制进入相机 相册 ios

#import <AssetsLibrary/AssetsLibrary.h>

ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
if (status == ALAuthorizationStatusRestricted || status == ALAuthorizationStatusDenied)
{
    // 无权限
    // do something...
}

ALAuthorizationStatus解释

ios 调用相机相册_强制进入相机 相册 ios_ios调用相机和相册

typedef NS_ENUM(NSInteger, ALAuthorizationStatus) {
    // 用户还没有关于这个应用程序做出了选择
    ALAuthorizationStatusNotDetermined NS_ENUM_DEPRECATED_IOS(6_0, 9_0) = 0, // User has not yet made a choice with regards to this application
    // 这个应用程序未被授权访问图片数据。用户不能更改该应用程序的状态,可能是由于活动的限制,如家长控制到位。
    ALAuthorizationStatusRestricted NS_ENUM_DEPRECATED_IOS(6_0, 9_0),        // This application is not authorized to access photo data.
                                            // The user cannot change this application’s status, possibly due to active restrictions
                                            //  such as parental controls being in place.
    // 用户已经明确否认了这个应用程序访问图片数据
    ALAuthorizationStatusDenied NS_ENUM_DEPRECATED_IOS(6_0, 9_0),            // User has explicitly denied this application access to photos data.
    // 用户授权此应用程序访问图片数据
    ALAuthorizationStatusAuthorized NS_ENUM_DEPRECATED_IOS(6_0, 9_0)        // User has authorized this application to access photos data.
} NS_DEPRECATED_IOS(6_0, 9_0, "Use PHAuthorizationStatus in the Photos framework instead");

在注解中我们可以看见苹果提示我们在Photos framework中可以使用PHAuthorizationStatus进行权限状态的判定

关于PHAuthorizationStatus

ios调用相机和相册_强制进入相机 相册 ios_ios 调用相机相册

在8.0系统之后,新加入了Photos.framework框架强制进入相机 相册 ios强制进入相机 相册 ios,我们可以借助框架中的PHAuthorizationStatus进行权限状态判定。

#import <Photos/PHPhotoLibrary.h>

PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied)
{ 
    // 无权限 
    // do something...
}

ios 调用相机相册_强制进入相机 相册 ios_ios调用相机和相册

typedef NS_ENUM(NSInteger, PHAuthorizationStatus) {
    PHAuthorizationStatusNotDetermined = 0, // User has not yet made a choice with regards to this application
    PHAuthorizationStatusRestricted,        // This application is not authorized to access photo data.
                                            // The user cannot change this application’s status, possibly due to active restrictions
                                            //   such as parental controls being in place.
    PHAuthorizationStatusDenied,            // User has explicitly denied this application access to photos data.
    PHAuthorizationStatusAuthorized         // User has authorized this application to access photos data.
} NS_AVAILABLE_IOS(8_0);

#import <AVFoundation/AVCaptureDevice.h>

AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied)
{
     // 无权限
     // do something...
}

强制进入相机 相册 ios_ios调用相机和相册_ios 调用相机相册

AVAuthorizationStatus解释

typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
     // 表明用户尚未选择关于客户端是否可以访问硬件
     AVAuthorizationStatusNotDetermined = 0,
     // 客户端未被授权访问硬件的媒体类型。用户不能改变客户机的状态,可能由于活跃的限制,如家长控制
      AVAuthorizationStatusRestricted,
     // 明确拒绝用户访问硬件支持的媒体类型的客户
     AVAuthorizationStatusDenied,
     // 客户端授权访问硬件支持的媒体类型
     AVAuthorizationStatusAuthorized
} NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
/*!
 @enum AVAuthorizationStatus
 @abstract
    Constants indicating the client's authorization to the underlying hardware supporting a media type.
 
 @constant AVAuthorizationStatusNotDetermined
    Indicates that the user has not yet made a choice regarding whether the client can access the hardware.
 @constant AVAuthorizationStatusRestricted
    The client is not authorized to access the hardware for the media type. The user cannot change
    the client's status, possibly due to active restrictions such as parental controls being in place.
 @constant AVAuthorizationStatusDenied
    The user explicitly denied access to the hardware supporting a media type for the client.
 @constant AVAuthorizationStatusAuthorized
    The client is authorized to access the hardware supporting a media type.
 */

有关相机、相册中图像的抓取参见:iOS从相册和照相机读取照片(UIImagePickerController)


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-122315-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 姬康
        姬康

        一般都是藏起来当祖国遭到毁灭打击核潜艇可以还击的一种威慑

      • 张钰诚
        张钰诚

        小编你是无知还是意淫

      热点图片
      拼命载入中...