首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swift MPRemoteCommandCenter nextTrackCommand被调用3次

Swift MPRemoteCommandCenter nextTrackCommand被调用3次
EN

Stack Overflow用户
提问于 2019-07-21 04:02:22
回答 1查看 617关注 0票数 0

我正在使用MPRemoteCommandCenter在我的音乐广播应用程序中更改歌曲。但当我按下锁定屏幕上的下一首曲目按钮时,它会跳3步。

下面是我的代码:

代码语言:javascript
复制
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次?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-22 05:12:13

问题可能是您多次调用setupRemoteTransportControls。每次执行此操作时,都会调用commandCenter.nextTrackCommand.addTarget并设置一个新的操作-目标对(而不删除现有的操作-目标对)。因此,当用户按下按钮时,所有这些对都会触发。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57128152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档