在 iPhone 应用程序中将 NSString 作为参数传递时出现问题
这是我的问题的背景。首先有一个线程启动:
-(void)run_thread: (NSObject* )file_path_NSObject
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *local_recordFilePath_NSString = (NSString *)file_path_NSObject;
NSLog(@"run thread : path %@ ", local_recordFilePath_NSString);
printf("Running Thread...\n");
runAllAudioRoutines(local_recordFilePath_NSString);
// more code....
上面的所有内容都正确打印到控制台。然后是被调用的方法:
void runAllAudioRoutines(NSString *file)
{
NSLog(@"running All Audio Routines method...\n");
NSString *truncatedFilePath = [file stringByReplacingOccurrencesOfString:@"LoopExtended.wav"
withString:@"recordedFile.wav"];
NSLog(@"FILE for !!!! --> %@",truncatedFilePath);
const char *location = [truncatedFilePath UTF8String];
const char *write_location = [file UTF8String];
int *vocal_data = read_wav(location, &size_vocal);
// more code....
奇怪的是,没有 NSLogs 打印根本。没有什么。没什么。拉链。然后应用程序在尝试将位置传递给 read wav 方法时崩溃(可能是因为字符串有问题)。
当我从使用 NSTemporaryDirectory 切换到 NSBundle 时,这一切都开始发生,但我不确定这是否与此有关。有什么建议吗?
我采纳了 Joetjah 的建议并开始使用:
[self runAllAudioRoutines:local_recordFilePath_NSString];
-(void)runAllAudioRoutines:(NSString*) file
现在我得到了:
第二次运行第二次Joetjah 的建议
Here is the context of my problem. First there is a thread that gets started:
-(void)run_thread: (NSObject* )file_path_NSObject
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *local_recordFilePath_NSString = (NSString *)file_path_NSObject;
NSLog(@"run thread : path %@ ", local_recordFilePath_NSString);
printf("Running Thread...\n");
runAllAudioRoutines(local_recordFilePath_NSString);
// more code....
Everything above prints correctly to the console. Then there is the method that gets called:
void runAllAudioRoutines(NSString *file)
{
NSLog(@"running All Audio Routines method...\n");
NSString *truncatedFilePath = [file stringByReplacingOccurrencesOfString:@"LoopExtended.wav"
withString:@"recordedFile.wav"];
NSLog(@"FILE for !!!! --> %@",truncatedFilePath);
const char *location = [truncatedFilePath UTF8String];
const char *write_location = [file UTF8String];
int *vocal_data = read_wav(location, &size_vocal);
// more code....
The strange thing is that none of the NSLogs print at all. Nothing. Nada. Zip. And then the app crashes when it tries to pass the location to the read wav method (presumably because there is something wrong with the string).
This all started to happen when I switched from using NSTemporaryDirectory to NSBundle, but I'm not sure if that has anything to do with it. Any advice?
I've taken a Joetjah's suggestion and started using instead:
[self runAllAudioRoutines:local_recordFilePath_NSString];
-(void)runAllAudioRoutines:(NSString*) file
and now I get this:
Second run with 2nd suggestion from Joetjah
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您收到的消息表明
SpeakHereController
未实现runAllAudioRoutines:
方法。您是否在正确的对象上调用了
runAllAudioRoutines:
?扩展: Objective-C 是一种动态语言。您可以在任何对象上调用任何方法,但如果该对象未实现该方法,应用程序将崩溃,并显示消息:
C++ 是一种静态语言。如果您尝试调用未为对象定义的函数,它将无法编译。在 Objective-C 中,它可以编译,但在运行时会出现错误。这就是发生在你身上的事情。
The message you are getting says that
SpeakHereController
doesn't implement the methodrunAllAudioRoutines:
.Did you call
runAllAudioRoutines:
on the right object?Expanding: Objective-C is a dynamic language. You can call any method on any object, but if the object doesn't implement the method, the app will crash, with the message:
C++ is a static languages. If you try to call a function that isn't defined for an object, it won't compile. In Objective-C, it will compile, but you get the error during runtime. This is what's happening to you.