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. [HttpException (0x80004005): The current identity

    [HttpException (0x80004005): The current identity (IIS APPPOOL\NationalUnion.Shared) does not have w ...

  2. 华为OJ平台——输出最小的k个数

    输入n个整数,输出其中最小的k个. 详细描述: 接口说明 原型: bool GetMinK(unsignedint uiInputNum, int *pInputArray, unsignedint ...

  3. svn服务端配置

    1.建立版本库 创建一个新的Subversion项目svnadmin create /var/www/svndata/njlrxx 配置允许用户jiqing访问cd /var/www/svndata/ ...

  4. 数据库连接池问题 Max Pool Size

    摘自: http://blog.csdn.net/chensirbbk/article/details/6225268 Timeout expired 超时时间已到. 达到了最大池大小 错误及Max ...

  5. Unieap3.5-前台js判断表单必录

    //用户信息字段检查 var custFrm=unieap.byId('custFrm'); var isValid=custFrm.validate(true); if(!isValid){ ret ...

  6. JavaScript中的Get和Set访问器

    今天要和大家分享的是JavaScript中的Get和Set访问器,和C#中的访问器非常相似. 标准的Get和Set访问器的实现   function Field(val){       this.va ...

  7. Chrome不能登录和同步的解决方法

    打开 C:\Windows\System32\drivers\etc 下的 hosts文件 #SmartHosts START #Google Services START .docs.google. ...

  8. [原]hdu2045 不容易系列三——LELE的RPG难题 (递推方程)

    本文出自:blog.csdn.net/svitter 原题:http://acm.hdu.edu.cn/showproblem.php?pid=2045 题意:中文不用我说了吧. 这个题目的关键就在于 ...

  9. HTML新特性之一----canvas

    <canvas id="me"></canvas>//申请一个canvas标签    <script>                var c ...

  10. URI中的常用属性

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA00AAACDCAIAAADea2ciAAAgAElEQVR4nOz9eTxU////j8/Y930pIb