Skip to content

Instantly share code, notes, and snippets.

@ruandao
Created November 21, 2014 07:05
Show Gist options
  • Select an option

  • Save ruandao/95ac57dbea6174a55dcb to your computer and use it in GitHub Desktop.

Select an option

Save ruandao/95ac57dbea6174a55dcb to your computer and use it in GitHub Desktop.
录音权限检测
AVAudioSession* session = [AVAudioSession sharedInstance];
if ([session respondsToSelector:@selector(requestRecordPermission:)]) {
[session performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
if (granted) {
// Microphone enabled code
NSLog(@"Microphone is enabled..");
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.recordBtn.selected) {
if ([AudioPlayingManager sharedInstance].audioPlayer) {
[[AudioPlayingManager sharedInstance].audioPlayer stop];
}
[self startAnimation];
[self startRecord];
self.recordBtn.selected = YES;
}
});
}
else {
// Microphone disabled code
NSLog(@"Microphone is disabled..");
// We're in a background thread here, so jump to main thread to do UI work.
dispatch_async(dispatch_get_main_queue(), ^{
[[[UIAlertView alloc] initWithTitle:LocStr(@"麦克风无法访问")
message:LocStr(@"魔音功能,需要麦克风进行录音\n\n打开麦克风方式: \n设置 / 隐私 / 麦克风")
delegate:nil
cancelButtonTitle:LocStr(@"知道了")
otherButtonTitles:nil] show];
});
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment