1

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. – Larme Dec 08 '17 at 09:26
  • 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 08 '17 at 10:23
  • Try `action:#selector(PlayerAndLyricsViewController.nextPressed(_:))` instead? See this: https://stackoverflow.com/questions/38673261/classname-has-no-member-functionname-when-adding-uibutton-target – Larme Dec 08 '17 at 10:24
  • 1
    Possible duplicate of ["classname has no member functionname" when adding UIButton target](https://stackoverflow.com/questions/38673261/classname-has-no-member-functionname-when-adding-uibutton-target) – Larme Dec 08 '17 at 10:25
  • Tried with 'action:#selector(PlayerAndLyricsViewController.nextPressed(_‌​:)) ' this as well. Still Same issue. – Dnyaneshwar Wakchaure Dec 08 '17 at 10:56
  • And then what's the error message when you tap nextPressed? – Larme Dec 08 '17 at 10:56
  • [_MPWeakInvocationTarget nextPressed]: unrecognized selector sent to instance – Dnyaneshwar Wakchaure Dec 08 '17 at 10:58
  • 1
    Finally got solution. I have to remove target in view did disapper. commandCenter.playCommand.removeTarget(self) commandCenter.pauseCommand.removeTarget(self) – Dnyaneshwar Wakchaure Jan 05 '18 at 09:16

0 Answers0