我正在使用MPRemoteCommandCenter在我的音乐广播应用程序中更改歌曲。但当我按下锁定屏幕上的下一首曲目按钮时,它会跳3步。
下面是我的代码:
func setupRemoteTransportControls() {
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.nextTrackCommand.addTarget { [unowned self] event in
print("Next")
self.stationIndex = (self.stationIndex+1)
self.currentStation = self.stations[self.stationIndex]
return .success
}
}输出为: Next Next Next
但我只按了一次按钮。如何才能只输出一次,每次3次?
发布于 2019-07-22 05:12:13
问题可能是您多次调用setupRemoteTransportControls。每次执行此操作时,都会调用commandCenter.nextTrackCommand.addTarget并设置一个新的操作-目标对(而不删除现有的操作-目标对)。因此,当用户按下按钮时,所有这些对都会触发。
https://stackoverflow.com/questions/57128152
复制相似问题