我的应用程序不支持返回以前的轨道,我想知道是否可以告诉锁屏音乐控件隐藏其倒带/上一轨道按钮。我使用MPNowPlayingInfoCenter将信息传达给锁定屏幕。

很简单的问题,可以解决吗?例如,仅显示“播放/暂停”和“向前跳过”?

最佳答案

从iOS 7.1开始,有一种方法可以自定义锁定屏幕和命令中心(可能还有许多其他附件)中可用的控件:MPRemoteCommandCenter

关于您的问题,您可以执行以下操作:

[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand.enabled = NO;
[MPRemoteCommandCenter sharedCommandCenter].skipBackwardCommand.enabled = NO;
[MPRemoteCommandCenter sharedCommandCenter].seekBackwardCommand.enabled = NO;

// You must also register for any other command in order to take control
// of the command center, or else disabling other commands does not work.
// For example:
[MPRemoteCommandCenter sharedCommandCenter].playCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(play)];

Please see this Stack Overflow answer for more general information about MPRemoteCommandCenter

10-06 02:54