Reputation: 4084
I am trying to code the simplest 'press a button an hear a sound' setup in xcode as possible, and am still managing to get some cryptic errors. Here is my code:
In .h file:
#import <AVFoundation/AVFoundation.h>
In .m file:
- (IBAction)beepButton:(UIButton *)sender {
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"buttonBeep"
ofType:@"mp3"]];
AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[click play];
//[click release];
}
When I try to compile my app, I get the errors:
Undefined symbols for architecture armv7s:
"_OBJC_CLASS_$_AVAudioPlayer", referenced from:
objc-class-ref in MyFirstViewController.o
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Am I doing something wrong? Any help is appreciated!
Upvotes: 0
Views: 177
Reputation: 318774
This is called a linker error. This is done after everything is compiled OK.
The problem is with the symbol _OBJC_CLASS_$_AVAudioPlayer
. What you do is ignore the part up through the dollar sign leaving you with AVAudioPlayer
.
Since you are trying to use the AVAudioPlayer
class and you import <AVFoundation/AVFoundation.h>
you need to realize that you must include the AVFoundation.framework
in your project.
If you look at the reference docs for AVAudioPlayer
, you will see that the docs state it is in the AVFoundation.framework
. This is how you know you need to add it to your project.
Upvotes: 2
Reputation: 1312
have u added the AVFoundation.framework? and make sure your .mp3 file appears in "copy bundle resources"
Upvotes: 1
Reputation: 17655
you have to add AVFoundation.framework
to your project, because it contains the AVAudioPlayer
class
Upvotes: 1