iOS 麦克风访问权限

  1. - (BOOL)canRecord  
  2. {  
  3.     __block BOOL bCanRecord = YES;  
  4.     if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending)  
  5.     {  
  6.         AVAudioSession *audioSession = [AVAudioSession sharedInstance];  
  7.         if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {  
  8.             [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {  
  9.                 if (granted) {  
  10.                     bCanRecord = YES;  
  11.                 } else {  
  12.                     bCanRecord = NO;  
  13.                 }  
  14.             }];  
  15.         }  
  16.     }  
  17.       
  18.     return bCanRecord;  
  19. }  
  20.   
  21. #pragma mark - Audio Recorder √  
  22.   
  23. /*开始录音*/  
  24. - (void)startToRecord:(id)sender  
  25. {  
  26.     if (![self canRecord]) {  
  27.         [[[UIAlertView alloc] initWithTitle:nil  
  28.                                     message:[NSString stringWithFormat:@"%@需要访问您的麦克风。\n请启用麦克风-设置/隐私/麦克风", [TIXAAppMonitor sharedMonitor].appName]  
  29.                                    delegate:nil  
  30.                           cancelButtonTitle:@"好"  
  31.                           otherButtonTitles:nil] show];  
  32.         return;  
  33.     }  
  34. }  

你可能感兴趣的:(123)