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. 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. 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):
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 (will open App #2 using canOpenUrl):
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
}
}