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