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

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -