日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS耳机操作

發布時間:2024/9/20 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS耳机操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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; }

轉載于:https://www.cnblogs.com/lovewx/p/4155782.html

總結

以上是生活随笔為你收集整理的iOS耳机操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。