有没有办法在iPhone中禁用录音功能?

时间:2011-09-22 11:31:44

标签: iphone voip audio-recording

我正在为iPhone制作VoIP应用程序。出于安全原因,必须禁止任何形式的录音。有可能这样做吗?如果是这样,怎么办?非常感谢!

编辑:该应用不适用于已越狱的iPhone。但是,私人框架是允许的。

1 个答案:

答案 0 :(得分:0)

你的.h文件中的

-

#import <AVFoundation/AVFoundation.h>

@interface recordViewController : UIViewController
        <AVAudioRecorderDelegate, AVAudioPlayerDelegate>
{
    AVAudioRecorder *audioRecorder;
    UIButton *playButton;
    UIButton *recordButton;
    UIButton *stopButton;
}
@property (nonatomic, retain) IBOutlet UIButton *playButton;
@property (nonatomic, retain) IBOutlet UIButton *recordButton;
@property (nonatomic, retain) IBOutlet UIButton *stopButton;

在你的.m文件中 -

- (void)viewDidLoad {
   [super viewDidLoad];
   playButton.enabled = NO;
   stopButton.enabled = NO;

   NSArray *dirPaths;
   NSString *docsDir;

   dirPaths = NSSearchPathForDirectoriesInDomains(
        NSDocumentDirectory, NSUserDomainMask, YES);
   docsDir = [dirPaths objectAtIndex:0];
   NSString *soundFilePath = [docsDir
       stringByAppendingPathComponent:@"sound.caf"];

   NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

   NSDictionary *recordSettings = [NSDictionary 
            dictionaryWithObjectsAndKeys:
            [NSNumber numberWithInt:AVAudioQualityMin],
            AVEncoderAudioQualityKey,
            [NSNumber numberWithInt:16], 
            AVEncoderBitRateKey,
            [NSNumber numberWithInt: 2], 
            AVNumberOfChannelsKey,
            [NSNumber numberWithFloat:44100.0], 
            AVSampleRateKey,
            nil];

  NSError *error = nil;

  audioRecorder = [[AVAudioRecorder alloc]
                  initWithURL:soundFileURL
                  settings:recordSettings
                  error:&error];
  [audioRecorder stop];
}

最后一行[audioRecorder stop]将确保录音停止。你可以做一些与你的应用类似的东西..