javascriptswifttvosapple-tvtvml

Apple TVML : Send APP to background when Menu button pressed on Siri remote


I don't know how to send app to background when "Menu" button is pressed from Siri remote in TVML app. I'm new to TVML development.

I was trying my hands on TVML development and created a small demo app where I'm playing video as soon as app launches. Now the problem is as per apple's guidelines, if I'm on my root page and i press menu button on siri remote then my app should go to background.

Now my app does't behaves accordingly. I tried many solutions like:

Registering my appDelegate() to become FirstResponder as following -

UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
self.becomeFirstResponder()

override func canBecomeFirstResponder() -> Bool {
    return true
}

override func remoteControlReceivedWithEvent(event: UIEvent?) {

}

Overriding pressBegin() and pressEnded() functions -

override func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
        super.pressesBegan(presses, withEvent: event)
        if presses.first?.type == UIPressType.Menu {


        }
}

override func pressesEnded(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
        super.pressesEnded(presses, withEvent: event)

        if presses.first?.type == UIPressType.Menu {

            exit(0)
        }
}

I have only one .js file named application.js and i kept it in a folder name server and accessing it as per apples guideline. I even downloaded apple's TVMLCatalogUsingTVMLTemplates project but I'm not able to understand where they have added code to submit app to background when we are on root menu and press menu button.

I just have one function in application.js and I'm calling it in App.onLaunch = function(options){}

Everything is working perfectly fine. I just want to know what code should i write in my application.js file or appDelegate that my app goes to background when menu button is pressed. Note: I dont have any hierarchy or child controllers all code executes from application.js Thus my application.js is root menu and i just have to submit app to background on menu button press.

Thank you in advance :)


Solution

  • It's strange that it's been a month and no one answered this question even when a bounty was set to this question!!! May be it was a silly question and no body bothered to answer!

    Any ways i got my answer so i am sharing it with every one.

    Actually the problem was the video player was not sensing the menu button press. I guess it was overriding this event and hence app was not submitting to background. I used the templates provided by apple and it started working!

    I guess we need to implement a DOM structure in our app and templates provided by apple already have it. So i manipulated the templates according to my needs and now i am getting menu button event on video player. So now a play list is my root controller and video is its child controller. When i press menu button while playing video, it pop back to the playlist controller and again on menu button press it submits to background. Finally with this solution my app is now approved and live on app store.