摄像头和相册使用权限设置

IOS7需要授权才能保存相片到相册
所以查询现在的授权状态是很有必要,有用到的可以参考我的代码

//保存按钮点击
-(void)saveBtnClicked:(id)sender
{
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
switch (author) {
case ALAuthorizationStatusNotDetermined:{
NSString *tips = @”请允许本App可以访问相册”;
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@”保存到相册需要授权” message:tips delegate:self cancelButtonTitle:@”确定” otherButtonTitles:nil] autorelease];
alert.tag = actionSheet_album_tag;
[alert show];
return;
break;
}

    case ALAuthorizationStatusRestricted:{
        NSString *tips = @"你的权限受限";
        UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"保存到相册需要授权" message:tips delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] autorelease];
        [alert show];
        return;
        break;
    }

    case ALAuthorizationStatusDenied:{
        NSString *tips = @"需要保存图片到相册\n请授权本App可以访问相册\n设置方式:手机设置->隐私->照片\n允许本App访问相册";
        UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"图片保存失败!" message:tips delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] autorelease];
        [alert show];
        return;
        break;
    }

    case ALAuthorizationStatusAuthorized:
        break;

    default:
        break;
}
[self doSaveToLocal];

}

  • (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
    [self doSaveToLocal];
    }

//保存到相册
-(void)doSaveToLocal
{
UIImageView photo = (UIImageView)[self.page viewWithTag:IMG_VIEW_TAG];
UIImageWriteToSavedPhotosAlbum(photo.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}

参考说明:

引用
当你第一次在应用中打开相册的时候,系统会提示你时候允许用户访问相册,如果你选择不允许的话,你以后在该应用中将无法访问相册。如果想要重新允许,那么需要你去“隐私设置”里面去设置。在程序中怎么获取用户是否拥有对相册的访问权限,然后做相应地操作呢,首先下面列出了相册的一些权限值和对应的含义
typedef NS_ENUM(NSInteger, ALAuthorizationStatus) {
ALAuthorizationStatusNotDetermined = 0, 用户尚未做出了选择这个应用程序的问候
ALAuthorizationStatusRestricted, 此应用程序没有被授权访问的照片数据。可能是家长控制权限。
ALAuthorizationStatusDenied, 用户已经明确否认了这一照片数据的应用程序访问.
ALAuthorizationStatusAuthorized 用户已授权应用访问照片数据.
}

我们在应用中只需要通过ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];相册的权限值, 然后做相应的操作。

1.在ios7之前摄像头是一直可以访问的,隐私设置选项中没有关闭相应软件的摄像头功能的选项。在ios7以后摄像头和相册一样增加了访问权限的设置,应用中第一次访问摄像头的时候,系统会询问你是否授权应用访问你的摄像头。摄像头的权限和相册的权限基本上一样,有:
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
AVAuthorizationStatusNotDetermined = 0,
AVAuthorizationStatusRestricted,
AVAuthorizationStatusDenied,
AVAuthorizationStatusAuthorized
} NS_AVAILABLE_IOS(7_0);

我们可以通过
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; 获取对摄像头的访问权限。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值