[iOS 系统]系统音频.相册.相机 权限判断
2016-06-30 10:57
387 查看
自己写的demo
留下以供自己回顾
需要添加的库
.m文件实现
留下以供自己回顾
需要添加的库
#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
相关文章推荐
- 解惑——iOS中成员变量和属性区别
- iOS防止用户截屏
- 趣谈iOS运行时之方法调用原理
- iOS设计模式(五) 中介者模式
- 仿猎豹垃圾清理(实现原理+源码)
- iOS开发-post请求向服务器发送json格式数据(数组或字典)
- 让iOS应用直接退出
- iOS 开发 Pch 文件的正确使用
- rn——小心得
- 清除缓存 iOS
- IOS友盟 社会化分享 > 社会化iOS组件 > 分享集成
- iOS--错误集锦--load the "xx" nib but the view outlet was not set.
- IOS ScrollView放大缩小点击位置并居中
- 修改IOS应用软件名称
- iOS 开发获取字体类型
- 文章标题
- 支付宝SDK
- [iOS 转]系统声音服务与震动
- iOS Provisioning Profile(Certificate)与Code Signing详解
- ios编程基础—视图