Apple TVOS应用程序调用另一个TVOS应用程序

时间:2015-12-18 18:10:31

标签: javascript swift tvos apple-tv tvml

我已经编写了一个显示视频库的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
}

}

1 个答案:

答案 0 :(得分:-1)

查看https://forums.developer.apple.com/message/7973#7973上的其他帖子不应该是

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

在来电应用中(在您的情况下为App1)?