I currently have my app setup like this:
I set an extern
variable in the AppDelegate.h because I've read they act as a global variable. Also added AudioToolbox framework.
AppDelegate.h
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
extern SystemSoundID tapSoundID;
@end
Next I added my code to load the tap sound in AppDelegate's didFinishLaunching method because I want the sound to be loaded as soon as the app's done starting.
AppDelegate.m
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Load Tap Sound
NSURL *tapSoundPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"tap" ofType:@"mp3"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)tapSoundPath, &tapSoundID);
return YES;
}
@end
Made sure to import the AppDelegate.h
class in my title screen view controller.
TitleScreen.h
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
And lastly, I'm using AudioServicesPlaySystemSound(tapSoundID);
to play the sound when a button is tapped.
TitleScreen.m
#import "TitleScreen.h"
@interface TitleScreen ()
@end
@implementation TitleScreen
- (IBAction)buttonToGameScreen:(id)sender{
AudioServicesPlaySystemSound(tapSoundID);
}
@end
I honestly thought this would work, and Xcode didn't show any warnings or errors until I tried to run the app:
Build Failed: Apple Mach-O Linker Errors
Undefined symbols for architecture armv7:
"_tapSoundID", referenced from:
-[AppDelegate application:didFinishLaunchingWithOptions:] in AppDelegate.o
-[TitleScreen goToGameplay:] in TitleScreen.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have no idea what these errors mean. I'm new to Objective-C/iOS programming, and I've spent hours trying to figure this out on my own but I just can't. Please help.