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
- (IBAction) NamedAction:(id)sender: (id) sender
has to variables named the same, probably the 2nd is a typo:
- (IBAction) NamedAction: (id) sender
And
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Jesus", CSFTR("WAV") NULL);
possibly missing a comma before the NULL?
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Jesus", CSFTR("WAV"), NULL);
What function is CSFTR? Apparently the compiler has never heard of it, which is what it is telling (in a rather weird way. Before C99, using a function without declaration was in implicit declaration, C99 removed that).
Could it be that you are trying to use a macro with a name that is just slightly different?
I'd really recommend that you avoid using Core Foundation functions. Especially since NSBundle and CFBundle can behave differently. Core Foundation and ARC especially is a combination that can make your brain hurt and can lead to memory leaks or crashes, unless you really know what you are doing.
you forgot to add a framework to your project which i suspect is AudioToolBox
Add -Wno-implicit-function-declaration in Other warnings flag and you will be able to compile the code. Although its not a good solution but it will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.