Ich bin ein Anfänger auf TVOS.AppleTV - tvos - Hybrid-App mit nativen und TVMLKIT - Kann nicht auf native App
Ich möchte eine Hybrid-App auf AppleTV mit einer nativen App und TVMLKIT erstellen. Meine native Anwendung ist nur eine einfache native App mit Schaltflächen (mit swift).
Wenn wir auf eine Schaltfläche klicken, starte ich eine Javascript-App mit TVLMKIT und TVJS.
Mein TVJS verwendet den Player, um ein Video anzuzeigen. Wenn das Video vorbei ist, möchte ich die TVJS App schließen und zurück zum nativen ViewController.
Mein Problem ist, dass wenn ich zurück zur nativen App, verliere ich den Fokus auf meine native Ansicht (die App ist eingefroren).
nativen Viewcontroller:
import UIKit
import TVMLKit
class ViewController: UIViewController, TVApplicationControllerDelegate {
var window: UIWindow?
var appController: TVApplicationController?
var appControllerContext = TVApplicationControllerContext();
static let TVBaseURL = "http://localhost:9001/"
static let TVBootURL = "\(ViewController.TVBaseURL)/client/js/application.js"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBOutlet weak var label: UILabel!
@IBOutlet weak var viewAd: UIView!
@IBAction func clickOnlaunchAd(sender: AnyObject) {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
guard let javaScriptURL = NSURL(string: ViewController.TVBootURL) else {
fatalError("unable to create NSURL")
}
appControllerContext.javaScriptApplicationURL = javaScriptURL
appControllerContext.launchOptions["BASEURL"] = ViewController.TVBaseURL
appController = TVApplicationController(context: appControllerContext, window: window,delegate: self)
}
@IBAction func clickOnChangeText(sender: AnyObject) {
label.text = "changed";
}
func appController(appController: TVApplicationController, didStopWithOptions options: [String : AnyObject]?) {
self.setNeedsFocusUpdate()
self.updateFocusIfNeeded()
}
func appController(appController: TVApplicationController, evaluateAppJavaScriptInContext jsContext: JSContext){
let notifyEventToNative : @convention(block) (NSString!) -> Void = {
(string : NSString!) -> Void in
print("[log]: \(string)\n")
self.appController?.stop()
}
jsContext.setObject(unsafeBitCast(notifyEventToNative, AnyObject.self), forKeyedSubscript: "notifyEventToNative")
}
}
Kurz vor "notifyEventToNative" von meiner TVJS nennen, nenne ich "navigationDocument.clear();" um die TVML-Ansicht zu löschen.
Ich kann meine native App sehen, aber ich kann nicht damit interagieren.
Irgendwelche Ideen? Danke.