iOS在7之后增加的麦克风权限的申请,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
AVAudioSession *avSession = [AVAudioSession sharedInstance];
if ([avSession respondsToSelector:@selector(requestRecordPermission:)]) {
[avSession requestRecordPermission:^(BOOL available) {
if (available) {
// 有麦克风权限
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[[[UIAlertView alloc] initWithTitle:@"无法录音" message:@"请在“设置-隐私-麦克风”选项中允许xx访问你的麦克风" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] show];
});
}
}];
}

iphone检测耳机插入/拔出

判断手机当前是否使用的是内置的麦克风(可以用此方法判断插入的耳机是否有麦克风)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
- (BOOL)isCurrentUsingBuildInMicrophone
{
NSError *error = nil;
BOOL result = YES;
result = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
if (!result) {
NSLog(@"%@", error);
return YES;
}
result = [[AVAudioSession sharedInstance] setActive:YES error:&error];
if (!result) {
NSLog(@"setActive failed");
return YES;
}
CFDictionaryRef ards;
UInt32 size = sizeof(CFDictionaryRef);
OSStatus os = AudioSessionGetProperty(kAudioSessionProperty_AudioRouteDescription, &size, &ards);
if (os == kAudioSessionNoError && ards && CFDictionaryGetValue(ards, kAudioSession_AudioRouteKey_Inputs)) {
NSArray *inputs = (__bridge NSArray *)CFDictionaryGetValue(ards, kAudioSession_AudioRouteKey_Inputs);
if (inputs && inputs.count > 0) {
for (NSDictionary *dic in inputs) {
NSString *type = dic[(__bridge NSString *)kAudioSession_AudioRouteKey_Type];
if ([type isEqualToString:(__bridge NSString *)kAudioSessionInputRoute_BuiltInMic]) {
return YES;
}
}
}
} else {
// 耳机没有mic
return YES;
}
return NO;
}

iOS耳机操作的更多相关文章

  1. iOS 耳机线控

    当你使用iphone的时候听音乐的时候,播放器在后台运行的时候,你仍然可以通过耳机来进行操作,完成曲目切换,快进,快退等功能!当然你的程序不一定是播放器应用,但是我们仍然可以让它具有这个功能,让用户通 ...

  2. iOS 数据库操作(使用FMDB)

    iOS 数据库操作(使用FMDB)   iOS中原生的SQLite API在使用上相当不友好,在使用时,非常不便.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB.Plausibl ...

  3. iOS——文件操作NSFileManager (创建、删除,复制,粘贴)

    iOS——文件操作NSFileManager (创建.删除,复制,粘贴)       iOS的沙盒机制,应用只能访问自己应用目录下的文件.iOS不像android,没有SD卡概念,不能直接访问图像.视 ...

  4. IOS文件操作的两种方式:NSFileManager操作和流操作

    1.常见的NSFileManager文件方法 -(NSData *)contentsAtPath:path //从一个文件读取数据 -(BOOL)createFileAtPath: path cont ...

  5. IOS数据库操作SQLite3使用详解(转)

    iPhone中支持通过sqlite3来访问iPhone本地的数据库.具体使用方法如下1:添加开发包libsqlite3.0.dylib首先是设置项目文件,在项目中添加iPhone版的sqlite3的数 ...

  6. 基于facebook-wda的iOS自动化操作实践记录

    [本文出自天外归云的博客园] 原理 对于iOS自动化操作,主要靠WebDriverAgent来完成.在Mac电脑上连接真机iPhone,运行WebDriverAgentRunner会在Mac端启动WD ...

  7. iOS数据库操作之coredata详细操作步骤

    CHENYILONG Blog iOS数据库操作之coredata详细操作步骤 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/ ...

  8. iOS 线程操作库 PromiseKit

    iOS 线程操作库 PromiseKit 官网:http://promisekit.org/ github:https://github.com/mxcl/PromiseKit/tree/master ...

  9. ios 文件操作(NSFileManager)

    IOS的沙盒机制,应用只能访问自己应用目录下的文件,iOS不像android,没有SD卡概念,不能直接访问图像.视频等内容. iOS应用产生的内容,如图像.文件.缓存内容等都必须存储在自己的沙盒内. ...

随机推荐

  1. PZISP自动下载软件运行时出现“应用程序无法启动,因为应用程序的并行配置不正确”

    在win7下以管理员身份运行“PZISP自动下载软件”时出现“应用程序无法启动,因为应用程序的并行配置不正确”时,是因为系统里面没有一些visual c++库 想一想,反正以后也要用上VS2010的, ...

  2. 从零开始安装Hadoop视频教程

    从零开始安装Hadoop视频教程 Hadoop 是一个能够对大量数据进行分布式处理的软件框架,用这种技术使得普通的PC服务器甚至一些近过时的服务器也能够发挥余热,组成大型集群系统,由于它的可伸缩性能够 ...

  3. Oracle笔记 十、PL/SQL存储过程

    --create or replace 创建或替换,如果存在就替换,不存在就创建 create or replace procedure p is cursor c is select * from ...

  4. C# winform编程中多线程操作控件方法

    private void Form1_Load(object sender, EventArgs e) { Thread newthread = new Thread(new ThreadStart( ...

  5. Eclipse 安装Groovy插件

    摘自: http://blog.csdn.net/boonya/article/details/45399901 步骤一: 下载eclipse4.3.0,地址:http://www.eclipse.o ...

  6. js,jquery获取下拉框选中的option

    js获取select选中的值: var sel=document.getElementById("select1"); var index = sel.selectedIndex; ...

  7. 条款20 STL函数对象

    继承标准STL的函数对象 1: struct PopLess : public atd::binary_function<state,state,bool> 2: { 3: bool op ...

  8. Min Stack [LeetCode 155]

    1- 问题描述 Design a stack that supports push, pop, top, and retrieving the minimum element in constant ...

  9. HTML 表单总结http://images2015.cnblogs.com/blog/1001203/201607/1001203-20160730200559841-2144892373.png

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  10. 软件工程 speedsnail 第二次冲刺2

    20150519 完成任务:划线第二天,能画出一条直黄线: 遇到问题: 问题1 划线的代码和移动的setcontentview冲突,无法同时显示 解决1 没有解决 明日任务: 线与移动共存