我将 WAV 文件名存储在一个数组中,包括扩展名。当我尝试加载它时,它需要删除扩展。如果我对扩展进行子串化,它会异常终止,而看似相同的字符串在硬编码时可以正常工作。
我也尝试使用stringByDeletingPathExtension方法,但同样崩溃。
此代码导致崩溃
NSString *fileName = [[currentWord.audioFile componentsSeparatedByString:@"."] objectAtIndex: 0];
SFCLog(@"fileName: %@",fileName);
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"];
CFURLRef BaseURL = (__bridge CFURLRef)[NSURL fileURLWithPath:path];
-[ViewController loadWord] [line 143] fileName: owe_fr
2012-08-20 17:50:21.561 Hello[8053:16a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
但是这段代码执行
NSString *fileName = @"owe_fr";
SFCLog(@"fileName: %@",fileName);
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"];
CFURLRef fluentBaseURL = (__bridge CFURLRef)[NSURL fileURLWithPath:path];