【发布时间】:2014-07-26 17:00:25
【问题描述】:
我已按照指示(我相信)Use your app delegate to share info between objects
但我不断收到以下错误:
[AppDelegate setBackgroundAudio:]:无法识别的选择器发送到 实例 0x10d822400 * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[AppDelegate setBackgroundAudio:]: 无法识别的选择器发送到实例 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];
}
【问题讨论】:
标签: objective-c