objective c - Call Swift code from an Apple TV TVML TVJS JavaScript App -


i have basic tvml application set up. simple events (such button press) handled via javascript (tvjs).

when user presses button (provided via tvml template) i'd code run in swift instead, manipulates ui elements.

what's best way this?

you can use evaluateappjavascriptin method in tvapplicationcontrollerdelegate below , write corresponding swift method in it; (swift side)

// mark: tvapplicationcontrollerdelegate func appcontroller(_ appcontroller: tvapplicationcontroller, evaluateappjavascriptin jscontext: jscontext){     let debug : @convention(block) (string!) -> void = {         (string : string!) -> void in         #if debug             print("[log]: \(string!)\n")         #endif     }     jscontext.setobject(unsafebitcast(debug, to: anyobject.self), forkeyedsubscript: "debug" (nscopying & nsobjectprotocol)!) } 

after can call method tvjs this; (js side)

debug('hello js swift...'); 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -