2011-09-22 54 views
0

我正在爲iPhone製作VoIP應用程序。出於安全原因,需要禁止任何形式的錄音。是否有可能這樣做?如果是這樣,該怎麼辦?非常感謝!有沒有辦法在iPhone中禁用錄音功能?

編輯:該應用程序不適用于越獄iPhone。但是,私人框架是允許的。

回答

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]是要確保錄音停止。你可以做類似於你的應用的東西。

+0

謝謝!我會嘗試使用代碼。 – phoenies

+0

儘管現在說的很遲,我用語音備忘錄試過這段代碼,但它不起作用... – phoenies

+0

據我調查,在進行VoIP對話時做背景記錄是不可能的,至少在非越獄的iPhone中是不可能的。所以沒有必要爲了安全目的而禁用它。這篇文章很有幫助。我會接受它。 – phoenies

相關問題