How are you testing this?
Rob
How are you testing this?
Rob
local function onKeyEvent(event) composer.gotoScene("game") end Runtime:addEventListener( "key", onKeyEvent )
Right now I’m just trying to get ANY key to transition to my game scene. I never see onKeyEvent get called. I know it’s one of those things where I’m doing something stupid and just haven’t seen it yet.
I’m building for the 9.1 tvOS simulator and testing there by bringing up the remote and simulating a click on the pad (or hitting play/pause, etc.)
Perhaps I should ship it over to my real device with TestFlight.
I would recommend testing on the real device. We know that the Xcode tvOS simulator doesn’t make good use of the remote.
You can tether the AppleTV to your Mac using the provided USB-C cable and have Corona install it on the device for you. That’s how I test.
Rob
The retail version of Apple TV doesn’t include the USB-C cable (at least mine didn’t). I got mine on Amazon.
I transferred my app to the Apple TV via TestFlight and still no go, so I’m pretty sure I’m doing something I’m just not seeing. I even rolled back to Corona 2795 to no avail. Once I figure it out I’ll report what I did stupid here.
I would put some print statements in your listener to see if it’s firing and what you’re getting.
Rob
I’ve stripped my app down to just the following main.lua (in addition to build.settings, config.lua, and all the tvOS icons).
local function onKeyEvent(event) print("onKeyEvent") end print("setting up key event listener") system.activate("controllerUserInteraction") Runtime:addEventListener( "key", onKeyEvent )
When I run in the Corona simulator I see the key event occur and everything works properly, but when I then build for the tvOS simulator and run it, I see the “setting up key event listener” message but I never see “onKeyEvent” for any remote input (using the virtual remote the apple simulator provides).
And earlier I tried on my real device by making ANY key advance to the next scene (because I wasn’t sure how to capture the print statements).
Am I just missing something basic here or is the a possibility there is an issue with Apple’s tvOS simulator? I can use the keyboard (arrows, enter, space) to navigate around the “settings” menu on the tvOS simulator, so it appears it handles keys appropriately.
Sorry for the confusion. Spent most the day on this and haven’t really gotten anywhere.
I decided to try a straight Xcode project and see if it worked. I found a simple one at
http://www.appcoda.com/tvos-introduction/
https://www.dropbox.com/sh/83i9ahb3nabc698/AACEmZp3ikCC3KB_2ZTTQlkNa/HelloWorld?dl=0
When I run it under the tvOS simulator I can use the ENTER key and the virtual remote to click the button. So I don’t think there is anything wrong with my environment. It’s just something about a Corona App and key events not getting through.
I see other threads on here of people successfully getting key events, but it’s unclear as to whether they are using the corona simulator, the tvOS simulator, or the real device. The only place I’ve gotten key events is the corona simulator.
Thanks,
doug
I was rereading the documentation at
https://docs.coronalabs.com/daily/guide/tvos/index.html
Maybe I’m misunderstanding something. The wording is unclear. Does this mean I MUST HAVE a MFi controller to test in the Corona Simulator? And where does Corona Enterprise fit into all of this? Why is it mentioned under the testing with tvOS/Xcode simulator?
Confused.
Doug
I’ve heard that you can pair your Apple TV remote with OS X at which it should work with the Corona Simulator. But it can’t be paired with two devices at once.
Apple’s Xcode simulator includes a window that does some remote basics, but its very limited in what it can do.
That’s why I asked “How” you were testing this. If you’re remote is paired with the AppleTV you can’t get the events in the Simulator. You have to test on the device.
I’m unsure why that note is under Enterprise, other than the Xcode simulator would be the natural way to test Enterprise builds if you’re not doing device testing. Where as for the SDK you can do a lot in the simulator.
What I do is process the OS X keyboard for Up/Down/Left/Right events. I capture the Return/Enter key to act like the buttonA event:
local function onKeyEvent( event ) phase = event.phase keyName = event.keyName print( event.phase, event.keyName ) if (keyName == "buttonStart" or keyName == "escape" or keyName == "menu") and phase == "down" then print( "Going Back" ) goMenu() return true elseif ( keyName == "buttonA" or keyName == "enter") and phase == "down" then print( "Trying to start level" ) playLevel() return true end return true end
Be aware we’ve removed Up/Down/Left/Right events from the touch sensitive pad on the remote because of excessive events and you should use the Axis events to detect swiping. There is another thread covering this.
Rob
Thanks Rob. Guess I will use the Corona Simulator and do the translation as you suggest. I did TestFlight Pew Pew to my Apple TV and it works, so definitely something I’m doing wrong in my code. I think I’m gonna buy another Apple TV I can hook up directly, since this TestFlight process is slow (and I have an upload stuck in processing now that never completed). Thanks for the help. Hoping to get my game out there in the next few months.
Yep, turns out my bad! The scene was refusing to transition because of a require error. I put an alert in on a key event and it’s showing. And of course on the Xcode simulator none of the key events get through as specified on the corona tv os guide. So… I either need to get a MFi remote for my Mac or another Apple TV that I can hook up directly to see log messages, otherwise it’s going to be a pain. Thanks for all the help.
Why can’t you hook up the one you have? Surely an USB-C cable and a USB extension cable to reach across the room would be cheaper than a second AppleTV (which is what I do)
Because I need an excuse to buy another one! I already have 3 3rd gens in the house and the 4th gen is downstairs nowhere near my computer. The new one I buy will be for development and then move down into the gym since there are so many good workout apps.
I paired my 4th gen Apple TV remote with my Mac. However it’s still unable to control the Corona built app. The remote does control the rest of the simulator (I can move through the menu settings). So it looks like the only way to test is with the real device. That really stinks.