简体   繁体   English

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

[英]Apple TVOS app that calls into another TVOS app

I have written a TVOS app that displays a video gallery, and this works fine, however, I need to be able to call into this TVOS app I created from another TVOS app. 我已经编写了一个显示视频库的TVOS应用程序,并且工作正常,但是,我需要能够调用从另一个TVOS应用程序创建的该TVOS应用程序。 I'm not sure how to go about this or if this is possible. 我不确定该怎么做,或者这是否可能。 Basically, I want to have one TVOS app that has maybe a button at the bottom that when you click it then another TVOS app will be dynamically loaded. 基本上,我想有一个TVOS应用程序,该应用程序的底部可能有一个按钮,当您单击它时,将动态加载另一个TVOS应用程序。 Another way to think of this is that I want a parent app to be a container for a child app - the parent app has no knowledge of the child app other than how to load it. 另一种思考方式是我希望父应用程序成为子应用程序的容器-父应用程序除了如何加载外不了解子应用程序。

Any help? 有什么帮助吗? Below is my code. 下面是我的代码。


App #2 (to be opened by App #1): 应用程序2(由应用程序1打开):

info.plist: info.plist:

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

AppDelegate.swift: 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: 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 (will open App #2 using canOpenUrl): 应用程序1(将使用canOpenUrl打开应用程序2):

info.plist: 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: 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
}

} }

Looking at another post at https://forums.developer.apple.com/message/7973#7973 shouldn't your https://forums.developer.apple.com/message/7973#7973上查看另一篇文章不应该

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

be in the caller app (App1 in your case)? 在呼叫者应用程序中(在您的情况下为App1)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM