【问题标题】:Apple TVOS app that calls into another TVOS app调用另一个 TVOS 应用程序的 Apple TVOS 应用程序
【发布时间】:2015-12-18 18:10:31
【问题描述】:

我编写了一个显示视频库的 TVOS 应用程序,它运行良好,但是,我需要能够调用我从另一个 TVOS 应用程序创建的这个 TVOS 应用程序。我不知道该怎么做,或者这是否可能。基本上,我想要一个 TVOS 应用程序,它的底部可能有一个按钮,当您单击它时,另一个 TVOS 应用程序将被动态加载。另一种思考方式是,我希望父应用成为子应用的容器 - 父应用除了如何加载子应用之外,对子应用一无所知。

有什么帮助吗?下面是我的代码。


App #2(由 App #1 打开):

info.plist:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>brightline123456</string>
</array>

AppDelegate.swift:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, TVApplicationControllerDelegate {

var window: UIWindow?
var appController: TVApplicationController?
static let TVBaseURL = "http://localhost:9001/"
static let TVBootURL = "\(AppDelegate.TVBaseURL)js/application.js"

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    window = UIWindow(frame: UIScreen.mainScreen().bounds)

    // 1
    let appControllerContext = TVApplicationControllerContext()

    // 2
    guard let javaScriptURL = NSURL(string: AppDelegate.TVBootURL) else {
        fatalError("unable to create NSURL")
    }
    appControllerContext.javaScriptApplicationURL = javaScriptURL
    appControllerContext.launchOptions["BASEURL"] = AppDelegate.TVBaseURL

    // 3
    appController = TVApplicationController(context: appControllerContext, window: window, delegate: self)
    return true
  }

}

Application.js:

var resourceLoader;

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

evaluateScripts(javascriptFiles, function(success) {
if(success) {
  // 3
  resourceLoader = new ResourceLoader(options.BASEURL);
   resourceLoader.loadResource(`${options.BASEURL}templates/RWDevConTemplate.xml.js`, function(resource) {
    var doc = Presenter.makeDocument(resource);
    doc.addEventListener("select", Presenter.load.bind(Presenter)); //add this line
    Presenter.pushDocument(doc);
  });
} else {
  var errorDoc = createAlert("Evaluate Scripts Error", "Error attempting to evaluate external JavaScript files.");
  navigationDocument.presentModal(errorDoc);
}
});
}

App #1(将使用 canOpenUrl 打开 App #2):

info.plist:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>brightline123456</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string></string>
        <key>CFBundleURLName</key>
        <string>com.brightline123456</string>
    </dict>
</array>

AppDelegate.swift:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, openURL:(NSURL), sourceApplication:(NSString), didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let url  = NSURL(string: "brightline123456://"); // Change the URL with your URL Scheme
    if UIApplication.sharedApplication().canOpenURL(url!) == true
    {
        UIApplication.sharedApplication().openURL(url!)
    }

    // Override point for customization after application launch.
    window = UIWindow(frame: UIScreen.mainScreen().bounds)

    return true
}

}

【问题讨论】:

  • 您是否尝试过使用自定义 URL 方案?
  • 在谷歌搜索自定义 URL 方案后,它看起来就是我想要的。你能指出我如何快速做到这一点的方向吗?我在网上找到的描述自定义 URL 方案的示例是用目标 c 编写的。感谢您的帮助!
  • 我没有任何使用自定义 URL 方案的专业知识,但困难的部分可能是设置您的属性列表,而不是它所使用的任何语言。如果我知道该怎么做,我会提供答案而不是评论。
  • 嘿,Daniel,感谢您的帮助,我在其他线程中遵循了您的建议,但是第二个 tvos 应用程序仍然无法从第一个 tvos 应用程序打开。我更新了上面的代码以显示 tvos app #1 的代码,然后还显示了 tvos app #2 的代码。关于可能出错的任何帮助?谢谢!

标签: javascript swift tvos apple-tv tvml


【解决方案1】:

查看https://forums.developer.apple.com/message/7973#7973 的另一篇帖子不应该是您的

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>brightline123456</string>
</array>

在调用者应用程序中(在您的情况下为 App1)?

【讨论】:

    猜你喜欢
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多