Ios 将背景音乐从ViewController暂停到AppDelegate

Ios 将背景音乐从ViewController暂停到AppDelegate,ios,objective-c,audio,Ios,Objective C,Audio,我有背景音乐,在我的应用程序代理中为我的所有ViewController声明 appdelegate.h @interface AppDelegate : UIResponder <UIApplicationDelegate, AVAudioPlayerDelegate>{ AVAudioPlayer *backgroundMusic; } 很好。但是如何在viewcontroller中暂停背景音乐? 我有一个开关按钮,但[背景音乐暂停];不起作用 - (IBAction)bac

我有背景音乐,在我的应用程序代理中为我的所有ViewController声明

appdelegate.h

@interface AppDelegate : UIResponder <UIApplicationDelegate, AVAudioPlayerDelegate>{

AVAudioPlayer *backgroundMusic;
}
很好。但是如何在viewcontroller中暂停背景音乐? 我有一个开关按钮,但[背景音乐暂停];不起作用

- (IBAction)backgroundMusicOnOff:(id)sender {

}

显示用于暂停音乐的代码。我没有任何暂停音乐的代码。代码应该是我的按钮,但是[背景音乐暂停];不起作用。我不知道为什么我的视图控制器看不到appdelegate中的音频播放器…暂停音乐的代码需要在你的appdelegate中。然后您从视图控制器调用该应用程序委派方法。您的意思是我需要一个停止在appdelegate中播放背景音乐,然后从视图控制器调用的方法?但是从那里我怎么能叫它呢?
- (IBAction)backgroundMusicOnOff:(id)sender {

}