Watchkit presentAudioRecordingControllerWithOutputURL 完成块问题
Watchkit presentAudioRecordingControllerWithOutputURL completion block issue
我只是想满足以下函数的参数以调出录音机。我相信问题出在完成块上。调试中给出的错误是:
presentAudioRecordingControllerWithOutputURL:preset:maximumDuration:actionTitle:completion: requires a non-NULL URL and completion block
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");
}
}];
我猜你的文件 URL recording
是错误的。您不能录制到“主包”。因此无法创建 NSURL 对象并发生非 NULL 错误。
例如,您可以按如下方式记录到 documents 目录中:
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);
}];
我只是想满足以下函数的参数以调出录音机。我相信问题出在完成块上。调试中给出的错误是:
presentAudioRecordingControllerWithOutputURL:preset:maximumDuration:actionTitle:completion: requires a non-NULL URL and completion block
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");
}
}];
我猜你的文件 URL recording
是错误的。您不能录制到“主包”。因此无法创建 NSURL 对象并发生非 NULL 错误。
例如,您可以按如下方式记录到 documents 目录中:
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);
}];