更新时间:2023-12-01 18:52:22
在 iOS7
无法获得麦克风授权的当前状态
。他们已经在 iOS8中给出了枚举
as AVAudioSessionRecordPermission
In iOS7
there is no way to get the current status of microphone authorization
.They have given the enum in iOS8
as AVAudioSessionRecordPermission
在 iOS7
中,您必须每次都要求权限
In iOS7
you have to request permission every time with
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
if (granted) {
NSLog(@"Permission granted");
}
else {
NSLog(@"Permission denied");
}
}];
以前曾问过同样的问题,但是没有这样的api,你知道当前状态如何 iOS8
The same question has been asked before but there is no such api with which you know current status as in iOS8
您可以参考在没有显示提示的情况下检查iOS 7上的麦克风权限
解决方案:
另一种选择是你可以显示弹出窗口
或者询问对于第一次的权限,并保存在 NSUserDefaults
中选择的用户选项的状态,而不是向前请求许可。
如果您不需要获得user的许可,您明确不需要调用此文档。当您第一次使用时,它将自动被 AVAudioSession
调用尝试录制
Another option is you can show the popup
or ask for permission first time and save the states of user option selected in NSUserDefaults
and than onwards do not ask for permission.
From docs you explicitly do not need to call this if each you do not need to get the permission of user.It will automatically called by AVAudioSession
first time when you try to record
录制音频需要用户的明确许可。应用程序的音频会话尝试使用音频输入路径
的第一个
时间,同时使用启用录音的类别(参见音频会话
类别),系统会自动提示用户输入
许可;或者,你可以调用requestRecordPermission:
在你选择的时候提示用户
Recording audio requires explicit permission from the user. The first time your app’s audio session attempts to use an audio input route while using a category that enables recording (see "Audio Session Categories"), the system automatically prompts the user for permission; alternatively, you can call requestRecordPermission: to prompt the user at a time of your choosing