在 iPhone 应用程序中将 NSString 作为参数传递时出现问题

发布于 2024-10-31 21:15:22 字数 1524 浏览 3 评论 0原文

这是我的问题的背景。首先有一个线程启动:

-(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:enter image description here

Second run with 2nd suggestion from Joetjahenter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑疤怪 2024-11-07 21:15:22

您收到的消息表明 SpeakHereController 未实现 runAllAudioRoutines: 方法。

您是否在正确的对象上调用了 runAllAudioRoutines:

扩展: Objective-C 是一种动态语言。您可以在任何对象上调用任何方法,但如果该对象未实现该方法,应用程序将崩溃,并显示消息:

“无法识别的选择器发送到实例...”

C++ 是一种静态语言。如果您尝试调用未为对象定义的函数,它将无法编译。在 Objective-C 中,它可以编译,但在运行时会出现错误。这就是发生在你身上的事情。

The message you are getting says that SpeakHereController doesn't implement the method runAllAudioRoutines:.

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:

"unrecognized selector sent to instance ..."

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文