Here is my code to clarify
viewcontroller.h
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface PlaySoundViewController : UIViewController {
CFURLRef soundFileURLRef;
SystemSoundID soundFileObject;
}
@property (readwrite) CFURLRef soundFileURLRef;
@property (readonly) SystemSoundID soundFileObject;
- (IBAction)playSound

id)sender;
@end
viewcontroller.m
#import "PlaySoundViewController.h"
#import <AudioToolbox/AudioServices.h>
@implementation PlaySoundViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName

NSString *)nibNameOrNil bundle

NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
//Get the main bundle for the app
CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle();
//Get URL to the sound file to play
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, CFSTR ("testFortune1"), CFSTR ("aif"), NULL);
//create a system sound object representing the sound file
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundFileObject);
}
//Play fortune to tap of a button
-(IBAction)playSound

id)sender{
AudioServicesPlaySystemSound(soundFileObject);
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation

UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
AudioServicesDisposeSystemSoundID(soundFileObject);
CFRelease(soundFileURLRef);
}
@end
What am I missing? I connected the button to the correct method in the interface builder already, but still no go.