[_MPWeakInvocationTarget pause]: unrecognized selector sent to instance

问题内容:

In PlayerAndLyricsViewController i have added

 class PlayerAndLyricsViewController: UIViewController{

  let commandCenter = MPRemoteCommandCenter.shared()

  override func viewDidLoad() {

         commandCenter.nextTrackCommand.addTarget(self, 
                action:#selector(nextPressed))
         commandCenter.nextTrackCommand.isEnabled = true
    }
   @IBAction func nextPressed(_ sender: Any) {
       // Some code
   }

}

I am using commandCenter to enable and disable for next, back and pause button.

When I initialise PlayerAndLyricsViewController first time Control Center working fine (Next, Pervious, Pause button), then I
pop the controller from navigation stack and again initialising this controller from other view controller . Now i am putting application in background and clicking on next button (Control center) or previous button throwing error(Crash)

[_MPWeakInvocationTarget pause]: unrecognized selector sent to
instance

or

[_MPWeakInvocationTarget nextPressed]: unrecognized selector sent to
instance

I am not getting whats going wrong. Please help me to solve this issue.

问题评论:

    
[_MPWeakInvocationTarget nextPressed] So the signature of the method is func nextPressed(), with no parameter (that’s not the method you wrote), and you did #selector(nextPressed), you didn’t put the correct selector.
    
Actually i tried with normal function as well still giving same issue. If this is an issue as you said then it should throw error every time but it is not. First time working fine but second time get crashed.
– Dnyaneshwar Wakchaure
Dec 8 at 10:23
    
Try action:#selector(PlayerAndLyricsViewController.nextPressed(_‌​:)) instead? See this: stackoverflow.com/questions/38673261/…
1  
    
Tried with ‘action:#selector(PlayerAndLyricsViewController.nextPressed(‌​_‌​:)) ‘ this as well. Still Same issue.
– Dnyaneshwar Wakchaure
Dec 8 at 10:56

原文地址:

https://stackoverflow.com/questions/47711137/mpweakinvocationtarget-pause-unrecognized-selector-sent-to-instance

添加评论

友情链接:蝴蝶教程