我遇到了麻烦
NSInvalidArgumentException 尝试使用 AudioFileCreateWithURL 时出现 nil 字符串参数
问题是,fileURL 打印NSLog
正确。我相信这是正确的格式:
文件://localhost/Users/me/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/1A617C0D-90CC-465C-9108-ECBCF85F075C/Documents/recording.wav
我猜 __bridge 转换可能会导致问题。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString* docDir = [paths objectAtIndex:0];
NSString* file = [docDir stringByAppendingString:@"/recording.wav"];
NSURL *fileURL = [NSURL fileURLWithPath:file];
NSLog(@"%@", fileURL);
OSStatus audioErr = noErr;
audioErr = AudioFileCreateWithURL( (__bridge CFURLRef)fileURL, kAudioFileWAVEType, &asbd, kAudioFileFlags_EraseFile, &audioFile);
我正在使用 ARC。我也试过这个:
audioErr = AudioFileCreateWithURL( (CFURLRef)CFBridgingRetain(fileURL), kAudioFileWAVEType, &asbd, kAudioFileFlags_EraseFile, &audioFile);
它导致了同样的异常。