3

在 .plist 中,我添加了正常的:http ://tinyurl.com/c7e9joy 当 iPhone 被锁定或我在应用程序之外并打开远程按钮时,我可以在那里看到应用程序徽标和标题,但它们不要反应。(我正在我自己的 iPhone 上进行测试。)

// Makes sure we are able to connect to the media buttons on the lock screen.
- (BOOL) canBecomeFirstResponder
{
return YES;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}

- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
NSLog(@"REMOTE");
if (receivedEvent.type == UIEventTypeRemoteControl) {

    switch (receivedEvent.subtype) {

        case UIEventSubtypeRemoteControlTogglePlayPause:
            [self playBtnPressed:nil];

            break;

        case UIEventSubtypeRemoteControlPreviousTrack:
            [self skipTrack:nil];
            break;

        case UIEventSubtypeRemoteControlNextTrack:
            [self skipTrack:nil];
            break;

        default:
            break;
    }
}
}
4

2 回答 2

2

您可能还需要添加:

- (BOOL)canBecomeFirstResponder {
    return YES;
}

任何子类都UIResponder需要实现这一点,否则它不会接受第一响应者状态。

于 2013-04-10T15:57:04.240 回答
2

您正在取消注册 viewWillDisapear 中的事件,这意味着只要该视图在手机上不可见,您就不会注册该事件。我会更改您注册和取消注册到 viewDidLoad 和 viewDidUnload 挂钩的位置。

于 2012-05-22T18:18:35.467 回答