gpt4 book ai didi

iphone - remoteControlReceivedWithEvent 从未调用过

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:06:08 25 4
gpt4 key购买 nike

我正在尝试允许 Remote 或耳塞在应用处于后台或屏幕锁定时播放和暂停音频。所以在 viewDidLoad 中我有:

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

然后我有:

- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {



if (receivedEvent.type == UIEventTypeRemoteControl) {



switch (receivedEvent.subtype) {



case UIEventSubtypeRemoteControlTogglePlayPause:

[self playOrStop];

break;



case UIEventSubtypeRemoteControlPreviousTrack:


break;



case UIEventSubtypeRemoteControlNextTrack:


break;



default:

break;

}

}


}

但是,它永远不会被调用。在后台运行已打开,AVSession 在 AppDelegate 中设置。我很茫然。

最佳答案

您可能还需要添加:

- (BOOL)canBecomeFirstResponder {
return YES;
}

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

关于iphone - remoteControlReceivedWithEvent 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13427572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com