-4

I am trying to make a simple soundboard app for the iphone, but have come across some troubles including implicit definition of function '...' is invalid in C99, about a few different functions.

My .h file looks like this:

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>


@interface ViewController : UIViewController

{

}

- (IBAction) Jesus: (id) sender;

@end

and my .m file code looks like this:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (IBAction) NamedAction:(id)sender: (id) sender
{
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Jesus",
    CSFTR("WAV") NULL);
    if  (soundFileURLRef) {
        CFStringRef url = CFURLGetString(soundFileURLRef);
        NSLog(@"string for URl is %@", (__bridge NSString *) url);
    }

    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);

}


@end

The error message I'm getting is:

Called object type 'int' is not a function or function pointer

4

4 回答 4

3

- (IBAction) NamedAction:(id)sender: (id) sender

必须变量命名相同,可能第二个是错字:

- (IBAction) NamedAction: (id) sender

soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Jesus", CSFTR("WAV") NULL);

可能在 NULL 之前缺少逗号?

soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Jesus", CSFTR("WAV"), NULL);

于 2012-12-06T21:54:09.007 回答
1

CSFTR 是什么功能?显然编译器从未听说过它,这就是它所说的(以一种相当奇怪的方式。在 C99 之前,使用没有声明的函数是隐式声明,C99 删除了它)。

可能是您尝试使用名称稍有不同的宏吗?

我真的建议您避免使用 Core Foundation 函数。特别是因为 NSBundle 和 CFBundle 的行为可能不同。尤其是 Core Foundation 和 ARC 的组合可能会使您的大脑受伤并可能导致内存泄漏或崩溃,除非您真的知道自己在做什么。

于 2014-02-21T18:13:21.423 回答
0

你忘了在你的项目中添加一个框架,我怀疑它是 AudioToolBox

于 2012-12-06T21:53:25.617 回答
0

在其他警告标志中添加-Wno-implicit-function-declaration,您将能够编译代码。虽然它不是一个好的解决方案,但它会起作用。

于 2020-10-29T06:34:49.343 回答