gpt4 book ai didi

ios - [NSURL initFileURLWithPath :]: nil string parameter with ARC

转载 作者:行者123 更新时间:2023-11-28 22:43:25 25 4
gpt4 key购买 nike

我遇到了问题

NSInvalidArgumentException nil string parameter when trying to use AudioFileCreateWithURL

问题是,fileURL 打印到 NSLog 是正确的。我相信这是正确的格式:

file://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);

它引起了同样的异常。

最佳答案

你看过http://lists.apple.com/archives/coreaudio-api/2010/Aug/msg00210.html了吗? ?他们使用 CFStringRef 让它工作。

// We have to encode spaces before sending it to CFURLCreateWithString. See CFURLCreateWithString returns NULL article http://markmail.org/message/5ugub2dvdaausdvf
CFStringRef fileName = (CFStringRef) recordedFile;
CFStringRef fileNameEscaped = CFURLCreateStringByAddingPercentEscapes(NULL, fileName, NULL, NULL, kCFStringEncodingUTF8);

// Create the URL
self.url = "" (CFStringRef)fileNameEscaped, NULL);
CHECK_NIL(url);

// Create audio file
OSStatus status = AudioFileCreateWithURL(url, kAudioFileWAVEType, &format, kAudioFileFlags_EraseFile, &audioFile);
NSAssert(status == noErr, @"AudioFileCreateWithURL fails");

关于ios - [NSURL initFileURLWithPath :]: nil string parameter with ARC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13847670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com