2015-06-10 18 views
1

我只是試圖滿足以下功能的參數來調出錄音機。我相信問題在於完成塊。在調試中給出的錯誤是:Watchkit presentAudioRecordingControllerWithOutputURL完成塊問題

presentAudioRecordingControllerWithOutputURL:預設:maximumDuration:actionTitle:完成:要求非NULL URL和完成塊

NSBundle* myBundle = [NSBundle mainBundle]; 
NSURL* recording = [myBundle URLForResource:@"recording" withExtension:@"mp4"]; 

[self presentAudioRecordingControllerWithOutputURL:recording 
              preset:WKAudioRecordingPresetWideBandSpeech 
            maximumDuration:5000 
             actionTitle:@"Recording" 
             completion:^(BOOL didSave, NSError *error) { 
              if (error != nil) 
              { 
               NSLog(@"Error: %@",error); 
              } 
              else if(didSave == YES) 
              { 
               NSLog(@"Saved the recording"); 
              } 
             }]; 

回答

2

我猜你的文件的URL recording是錯誤的。您無法錄製到「主包」「。所以NSURL對象不能被創建併發生非NULL錯誤。

例如,你將能夠記錄到文件目錄如下:

NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                 NSUserDomainMask,YES); 
NSString *path = [[filePaths firstObject] stringByAppendingPathComponent:@"recording.mp4"]; 
NSURL *fileUrl = [NSURL fileURLWithPath:path]; 

[self presentAudioRecordingControllerWithOutputURL:fileUrl 
              preset:WKAudioRecordingPresetWideBandSpeech 
            maximumDuration:5000 
             actionTitle:@"Recording" 
             completion:^(BOOL didSave, NSError * __nullable error) { 

              NSLog(@"didSave:%d, error:%@", didSave, error); 
             }]; 
+0

謝謝,改變記錄文件,以文件工作的位置! –