ios7新增api requestRecordPermission
api 说明:
- (void)requestRecordPermission:(PermissionBlock)response
Description
Request the user’s permission for audio recording.
Recording audio requires explicit permission from the user. The system automatically prompts the user for permission if you use any session categories that enable recording, or you can call this method to prompt for permission at a time of your choosing. After
the user grants or denies permission, the system remembers the choice for future use in the same app. If permission is not granted, or if the user has not yet responded to the permission prompt, any audio recording sessions record only silence.
The response parameter is a block of the PermissionBlock type, whose sole parameter indicates whether the user granted or denied permission to record. This method always returns immediately: if the user has previously granted or denied recording permission,
it executes the block when called; otherwise, it displays an alert and executes the block only after the user has responded to the alert.
Parameters
response
A block to be called when recording permission has been granted or denied.
Availability iOS (7.0 and later)
新增api,获取录音权限.
返回值,YES为无拒绝,NO为拒绝录音.
-(BOOL)canRecord
{__block BOOL bCanRecord = YES;
if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending)
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
[audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
if (granted) {
bCanRecord = YES;
}
else {
bCanRecord = NO;
dispatch_async(dispatch_get_main_queue(), ^{
[[[[UIAlertView alloc] initWithTitle:nil
message:@"app需要访问您的麦克风。\n请启用麦克风-设置/隐私/麦克风"
delegate:nil
cancelButtonTitle:@"关闭"
otherButtonTitles:nil] autorelease] show];
});
}
}];
}
}
return bCanRecord;
}
本文介绍了iOS7中如何使用AVAudioSession请求录音权限。系统会在使用特定录音类别时自动请求权限,或者你可以调用requestRecordPermission方法在合适时机提示用户。用户的选择会被记住,未获许可的情况下录音会保持静音。该方法会立即返回,并通过响应块告知用户是否授权。同时,还提供了一个方法canRecord来检查当前是否可以录音。
491

被折叠的 条评论
为什么被折叠?



