gpt4 book ai didi

tvos - 如何在 tvOS 应用程序中同时使用 native 和 TVML?

转载 作者:行者123 更新时间:2023-12-02 21:01:59 27 4
gpt4 key购买 nike

是否可以在 tvOS 应用程序中同时使用 native View / Controller 和 TVML?似乎使用 TVML 需要您设置一个“应用程序 Controller ”而不是普通的 View Controller 。如何在 tvOS 应用程序中同时使用 TVML 和 native 组件?

最佳答案

是的,您可以在同一个应用程序中同时使用 Native 和 TVML。您可以在App Delegate的evaluateAppJavaScriptInContext方法中注册您的类对象。

func appController(appController: TVApplicationController, evaluateAppJavaScriptInContext jsContext: JSContext)
{

jsContext.setObject(TestClass(), forKeyedSubscript: "testClassObj")
}

您的 TestClass 应采用 TestClassExport 协议(protocol)。 (我的 TestClass 使用 Objective C 编写。您也可以使用 Swift 编写。)

@protocol TestClassExport <JSExport>

- (NSString*)log:(NSString*)string;

@end

@interface TestClass : NSObject <TestClassExport>

-(NSString*)log:(NSString*)string;

@end

现在您可以从 Javascript 调用测试类日志方法:

testClassObj.log('Call from JS');

如果您想显示任何 Controller ,那么您可以实现将 Controller 推送到 TVApplicationController 中的方法。

[_tvAppController.navigationController pushViewController:controller animated:YES completion:nil];

查看此链接了解更多详细信息 - https://forums.developer.apple.com/thread/18430

关于tvos - 如何在 tvOS 应用程序中同时使用 native 和 TVML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37765886/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com