Je suis un débutant sur TVOS. Je voudrais créer une application hybride sur AppleTV en utilisant une application native et TVMLKIT. Mon application native est juste une simple application native avec des boutons (en utilisant swift). Lorsque nous cliquons sur un bouton, je lance une application javascript en utilisant TVLMKIT et TVJS.AppleTV - tvos - Application hybride en utilisant natif et TVMLKIT - Impossible de revenir à l'application native
Mon TVJS utilise le lecteur pour afficher une vidéo. Une fois la vidéo terminée, je souhaite fermer l'application TVJS et revenir au ViewController natif.
Mon problème est que lorsque je reviens à l'application native, je perds l'accent sur ma vue native (l'application est gelée).
ViewController natif:
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")
}
}
Juste avant d'appeler "notifyEventToNative" de mon TVJS, j'appelle "navigationDocument.clear();" pour effacer la vue TVML.
Je peux voir mon application native mais je ne peux pas interagir avec elle.
Des idées? Merci.