2020-11-29

Swift addTarget does not get removed?

The target of nextTrackCommand is called multiple times when I navigate back from a screen and enter the screen again even tho i remove the target in viewWillDisappear. What did I do wrong?

override func viewDidLoad() {
    super.viewDidLoad()

    UIApplication.shared.beginReceivingRemoteControlEvents()

    MPRemoteCommandCenter.shared().nextTrackCommand.addTarget { [unowned self] (_) -> MPRemoteCommandHandlerStatus in
        print("go to next track")
        return .success
    }
}

override func viewWillDisappear(_ animated: Bool) {
    MPRemoteCommandCenter.shared().nextTrackCommand.removeTarget(self)
}


from Recent Questions - Stack Overflow https://ift.tt/39s6WRQ
https://ift.tt/eA8V8J

No comments:

Post a Comment