我有一个应用程序在iOS 4.3.3上运行良好 . 但是我发现在iOS 5上存在一些问题 . 这个应用程序播放avaudioplayer的mp3文件,遥控器在iOS 5上运行不正常 .

此应用程序中有四个视图控制器 . 我在每个视图控制器上添加以下代码,以实现远程控制的功能 . 问题是,当视图控制器第一次打开时 . 遥控器按钮效果很好,甚至应用程序在后台运行或锁定屏幕 . 但是,当我单击其他视图控制器并返回上一个时,遥控器不再工作 . 但每次调用canBecomeFirstResponder函数 .

我甚至试图把[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];在委托函数(BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions :( NSDictionary *)launchOptions它不起作用 .

我不明白为什么会这样 . 它折磨了我好几天 . 有没有更好的方法在多个视图控制器中实现远程控制功能?

顺便说一下,我将UIBackgroundModes音频密钥添加到info.plist中 . 这个应用程序在后台运行良好 .

任何帮助将不胜感激 .

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillAppear:(BOOL)animated {
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}  
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
- (BOOL) canBecomeFirstResponder {
NSLog(@"Can be first responder!");
return YES;
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)event
{
if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
    NSLog(@"UIEventSubtypeRemoteControlTogglePlayPause");
    [self playAndpause:nil];
}
}