0

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
}

}

jre247
  • 1,787
  • 5
  • 21
  • 28
  • Have you tried using a custom URL scheme? – Glenn Howes Dec 18 '15 at 18:12
  • After googling custom URL scheme it looks like that's what I want. Are you able to point me in the direction of how I could do this with swift? The example i found online of someone describing custom URL scheme was written in objective c. Thanks for your help! – jre247 Dec 18 '15 at 18:24
  • I don't have any specialized knowledge of using custom URL schemes, but the hard part is probably setting up your property lists and not whatever language it is in. If I knew exactly how to do it, I'd have provided an answer instead of a comment. – Glenn Howes Dec 18 '15 at 19:16
  • Check out: [How do I open another application with tvOS?](http://stackoverflow.com/questions/32677304/how-do-i-open-another-application-with-tvos) – Daniel Storm Dec 19 '15 at 14:03
  • Hey Daniel, thanks for your help and I followed your advice in that other thread, however the second tvos app still doesn't open from the first tvos app. I updated my code above to show the code for tvos app #1 and then also the code for tvos app #2. Any help as to what's possibly going wrong? Thanks! – jre247 Dec 21 '15 at 19:56

1 Answers1

-1

Looking at another post at https://forums.developer.apple.com/message/7973#7973 shouldn't your

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

be in the caller app (App1 in your case)?

Liam
  • 27,717
  • 28
  • 128
  • 190
MidiGlitch
  • 11
  • 2