[iOS 系统]系统音频.相册.相机 权限判断

自己写的demo
留下以供自己回顾

需要添加的库

#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>

.m文件实现



#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>


#define SoundID 1317
@interface ViewController (){

}
@property (weak, nonatomic) IBOutlet UITextField *soundtextfiled;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    for (UIView *v in self.view.subviews) {
        if ([v isKindOfClass:[UITextField class]]) {
            UITextField *t = (UITextField*)v;
            [t resignFirstResponder];
        }

    }
}

// 点击发出系统音
- (IBAction)sound:(id)sender {

    AudioServicesPlaySystemSound([_soundtextfiled.text intValue]);

}
// 点击触发系统震
- (IBAction)vibration:(id)sender {
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

}
//点击检测相机权限
- (IBAction)camera:(id)sender {

    //ios7之前系统默认拥有权限
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (authStatus == AVAuthorizationStatusDenied) {
            _soundtextfiled.placeholder = @"您还未为本App开通相机权限";
        }else{
            _soundtextfiled.placeholder = @"本App拥有相机开启权限";
        }
    }

}
// 点击检测相册权限
- (IBAction)photo:(id)sender {
    //iOS8 以下系统默认有权限
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {
        ALAuthorizationStatus authStates = [ALAssetsLibrary authorizationStatus];
        if ( authStates ==  ALAuthorizationStatusDenied) {
            _soundtextfiled.placeholder = @"您没有访问相册的权限";
        }
        else{
            _soundtextfiled.placeholder = @"您拥有访问相册的权限";
        }
    }
}
@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值