您可以在Apple TV而不是外部服务器上托管TVJS文件吗?

郡友关系

我已经从Apple下载了TVMLCatalog应用程序。该代码分为两部分。

  1. 客户端-包含TVML和TVJS文件
  2. TVMLCatalog项目-这是设置TVML / TVJS的基本Xcode项目

我正在尝试将客户端TVJS文件与TVMLCatalog项目托管在同一包中

我已将AppDelegate didFinishLaunching更改如下:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    window = UIWindow(frame: UIScreen.mainScreen().bounds)

    /*
    Create the TVApplicationControllerContext for this application
    and set the properties that will be passed to the `App.onLaunch` function
    in JavaScript.
    */
    let appControllerContext = TVApplicationControllerContext()

    /*
    The JavaScript URL is used to create the JavaScript context for your
    TVMLKit application. Although it is possible to separate your JavaScript
    into separate files, to help reduce the launch time of your application
    we recommend creating minified and compressed version of this resource.
    This will allow for the resource to be retrieved and UI presented to
    the user quickly.
    */

    TVBootURL = NSBundle.mainBundle().pathForResource("application", ofType: "js")!
    TVBaseURL = TVBootURL.stringByReplacingOccurrencesOfString("application.js", withString: "")
    if let javaScriptURL = NSURL(string: TVBootURL) {
        appControllerContext.javaScriptApplicationURL = javaScriptURL
    }

    appControllerContext.launchOptions["BASEURL"] = TVBaseURL

    if let launchOptions = launchOptions as? [String: AnyObject] {
        for (kind, value) in launchOptions {
            appControllerContext.launchOptions[kind] = value
        }
    }

    appController = TVApplicationController(context: appControllerContext, window: window, delegate: self)

    return true
}

这是一个截图,演示了如何导入客户端Xcode截图

当我运行项目(仅在模拟器上进行测试)时,在AppleTV模拟器屏幕上显示以下消息:

启动应用程序时出错-该操作无法完成。(TVMLKitErrorDomain错误3。)

我可以像这样从本地加载TVJS文件吗?

郡友关系

经过深层的谷歌搜索,我能够找到答案。这个人的帖子确实对我有帮助:

http://thejustinwalsh.com/objective-c/tvml/2015/09/20/tvml-without-the-webserver.html

该示例在Objective-C中,但我已经实现了Swift解决方案。

这是我从原始帖子中更改代码的方式:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    window = UIWindow(frame: UIScreen.mainScreen().bounds)

    /*
    Create the TVApplicationControllerContext for this application
    and set the properties that will be passed to the `App.onLaunch` function
    in JavaScript.
    */
    let appControllerContext = TVApplicationControllerContext()

    /*
    The JavaScript URL is used to create the JavaScript context for your
    TVMLKit application. Although it is possible to separate your JavaScript
    into separate files, to help reduce the launch time of your application
    we recommend creating minified and compressed version of this resource.
    This will allow for the resource to be retrieved and UI presented to
    the user quickly.
    */

    if let javaScriptURL = NSBundle.mainBundle().URLForResource("application", withExtension: "js"){
        appControllerContext.javaScriptApplicationURL = javaScriptURL
    }

    let TVBaseURL = appControllerContext.javaScriptApplicationURL.URLByDeletingLastPathComponent

    appControllerContext.launchOptions["BASEURL"] = TVBaseURL?.absoluteString

    if let launchOptions = launchOptions as? [String: AnyObject] {
        for (kind, value) in launchOptions {
            appControllerContext.launchOptions[kind] = value
        }
    }

    appController = TVApplicationController(context: appControllerContext, window: window, delegate: self)

    return true
}

重要说明:您需要在TVJS文件中更改文件路径引用,以反映新的包路径结构。

Application.js中的示例:

App.onLaunch = function(options) {
var javascriptFiles = [
    `${options.BASEURL}js/ResourceLoader.js`,
    `${options.BASEURL}js/Presenter.js`
];
...

变成:

App.onLaunch = function(options) {
var javascriptFiles = [
    `${options.BASEURL}ResourceLoader.js`,
    `${options.BASEURL}Presenter.js`
];
...

和这条路:

${options.BASEURL}templates/Index.xml.js

变成:

${options.BASEURL}Index.xml.js

[更新]

迅捷3

重要提示:将application.js文件添加到项目的目标;启动新项目时,默认情况下不添加此功能。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    window = UIWindow(frame: UIScreen.main.bounds)

    // Create the TVApplicationControllerContext for this application and set the properties that will be passed to the `App.onLaunch` function in JavaScript.
    let appControllerContext = TVApplicationControllerContext()

    // The JavaScript URL is used to create the JavaScript context for your TVMLKit application. Although it is possible to separate your JavaScript into separate files, to help reduce the launch time of your application we recommend creating minified and compressed version of this resource. This will allow for the resource to be retrieved and UI presented to the user quickly.
    if let javaScriptURL = Bundle.main.url(forResource: "application", withExtension: "js"){
        appControllerContext.javaScriptApplicationURL = javaScriptURL
    }

    let TVBaseURL = appControllerContext.javaScriptApplicationURL.deletingLastPathComponent()

    appControllerContext.launchOptions["BASEURL"] = TVBaseURL.absoluteString

    if let launchOptions = launchOptions {
        for (kind, value) in launchOptions {
            appControllerContext.launchOptions[kind.rawValue] = value
        }
    }

    appController = TVApplicationController(context: appControllerContext, window: window, delegate: self)

    return true
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

可以在我自己的服务器上托管电报吗?

您可以获得Apple Watch的大致电池百分比吗?

您可以在Apple iWork Numbers中使用JavaScript或文本公式吗?

您可以在应用程序中使用Apple Watch Crown吗?

从内容脚本中,我可以对服务器上托管的REST API进行ajax调用吗?

我可以在一台服务器上托管Angular2前端和Golang后端吗

我可以在Google云功能上托管Node.js GRPC服务器吗?

我可以在两个或多个服务器上托管一个电子邮件帐户吗?

您可以“ Ping” Roblox服务器吗?

您可以估计服务器的位置吗?

您可以在graphql服务器架构文件中使用片段吗

您可以使用RandomAccessFile访问远程FTP服务器上的文件吗?

您可以使用服务器捆绑文件并减少HTTP请求吗?

您可以在将通行证添加到Apple Wallet时控制通行证的顺序吗?

您可以使用基于AWS Route 53延迟的路由来解析AWS外部的服务器吗?

我们可以从任何其他客户端(jboss客户端)调用weblogic服务器上托管的EJB(Enterprise Java Bean)吗?

您可以安装UEFI吗?

您可以连锁物业吗?

我可以从TVJS中检测到Apple TV应用何时再次变为活动状态吗?

Landscape可以监视托管在其上的服务器吗?

您可以秘密运行python文件吗?

您可以scp设备文件吗?

您可以上传文件吗

您可以链接到HTML文件吗?

您可以导入.so文件吗?

您可以卷曲来自GitLab的文件吗?

您可以恢复文件的先前版本吗?

您可以绕过文件系统权限吗?

网络托管服务器也可以成为域名服务器吗?