Lockscreen中的iPod控件适用于自己的应用程序 [英] iPod Controls in Lockscreen for own App
问题描述
如何在我自己的应用程序中使用锁屏iPod控件?
How can I use the Lock Screen iPod Controls for my own App?
我尝试了MPNowPlayingInfoCenter,但是如果我设置了信息,它将不会显示在任何地方;不在锁屏上,也不在AppleTV上播放。
I tried MPNowPlayingInfoCenter, but if I set the information it won't be displayed anywhere; Not on the lock-screen and not in airplay on AppleTV.
我使用AVPlayer播放我的音频文件。
I use the AVPlayer to play my audio files.
推荐答案
查看远程控制多媒体文档。
以下是如何在 UIViewController中监听远程控制事件
子类。首先,让您的控制器参与响应者链,否则事件将被转发给应用程序代表:
Here’s how to listen for remote control events in a UIViewController
subclass. First, make your controller participate in the responder chain, otherwise the events will be forwarded to the app delegate:
- (BOOL)canBecomeFirstResponder
{
return YES;
}
在适当的情况下,告诉应用程序开始接收事件并使控制器成为第一个响应者:
Where appropriate, tell the application to start receiving events and make your controller the first responder:
// maybe not the best place but it works as an example
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
然后回复:
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
[self playOrStop: nil];
break;
case UIEventSubtypeRemoteControlPreviousTrack:
[self previousTrack: nil];
break;
case UIEventSubtypeRemoteControlNextTrack:
[self nextTrack: nil];
break;
default:
break;
}
}
}
这篇关于Lockscreen中的iPod控件适用于自己的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!