I have followed the instructions (I believe) Use your app delegate to share info between objects
but I keep getting the following errors:
[AppDelegate setBackgroundAudio:]: unrecognized selector sent to instance 0x10d822400 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate setBackgroundAudio:]: unrecognized selector sent to instance 0x10d822400'
MyAppDelegate.h
@interface MyAppDelegate : NSObject{
AVAudioPlayer *backgroundAudio;
}
@property (strong, nonatomic) AVAudioPlayer *backgroundAudio;
@end
MyAppDelegate.m
@implementation MyAppDelegate
@synthesize backgroundAudio;
@end
ViewController.m
MyAppDelegate *app_delegate = (MyAppDelegate*) [UIApplication sharedApplication].delegate;
backgroundAudioPath = [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"];
backgroundAudioURL = [NSURL fileURLWithPath:backgroundAudioPath];
app_delegate.backgroundAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundAudioURL error:Nil];
[app_delegate.backgroundAudio setDelegate:self];
[app_delegate.backgroundAudio setNumberOfLoops:-1];
[app_delegate.backgroundAudio prepareToPlay];
if (app_delegate.backgroundAudio != nil){
[app_delegate.backgroundAudio stop];
[app_delegate.backgroundAudio setCurrentTime:0];
[app_delegate.backgroundAudio play];
}