I created a simple AppleTV project to display multiple videos by category, watching and playing videos works fine. It was implemented as a client-server application using TVML and TVJS, so most of the application logic is in Javascript files. They are statically generated in the background from dynamic content on a regular basis.
Then I added the TopShelf extension to the application, which pulls some popular videos from the API, it also works great, pulls the video on hold.
The problem I am facing is to detect and respond to a user selecting a video from the top shelf. I created an exampletvapp: // URL scheme, which I registered in my plist file.
I also added displayURL and playURL to TVContentItems. When you select one of the videos, my application launches as expected, but does not actually handle the playback of this video.
In my AppDelegate file, I added print statements to print launchOptions, and also added an openUrl function that calls, but only registers this if I close the application and quickly select something from the top shelf before the application closes and I lose the session debugging.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
print("App Launch: \(launchOptions)")
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let appControllerContext = TVApplicationControllerContext()
guard let javaScriptURL = NSURL(string: AppDelegate.TVBootURL) else {
fatalError("unable to create NSURL")
}
appControllerContext.javaScriptApplicationURL = javaScriptURL
appControllerContext.launchOptions["BASEURL"] = AppDelegate.TVBaseURL
if let options = launchOptions {
for (kind, value) in options {
if let kindStr = kind as? String {
appControllerContext.launchOptions[kindStr] = value
}
}
}
appController = TVApplicationController(context: appControllerContext, window: self.window, delegate: self)
return true
}
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
guard let javaScriptURL = NSURL(string: AppDelegate.TVBootURL) else {
fatalError("unable to create NSURL")
}
let appControllerContext = TVApplicationControllerContext()
appControllerContext.javaScriptApplicationURL = javaScriptURL
appControllerContext.launchOptions["BASEURL"] = AppDelegate.TVBaseURL
for (kind, value) in options {
appControllerContext.launchOptions[kind] = value
}
appController = TVApplicationController(context: appControllerContext, window: self.window, delegate: self)
return true
}
func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool {
print("handle Url called")
}
JavaScript:
App.onLaunch = function(options) {
var javascriptFiles = [
`${options.BASEURL}js/ResourceLoader.js`,
`${options.BASEURL}js/Presenter.js`
];
console.log("options", options);
console.log JS, , , . , Player TopShelf. , URL- , , ajax , TVContentItem.
, : topshelf ( Swift) javascript . javascript, console.log? , .
UPDATE:
, ( Apple), Safari JS Context Apple TV "" > "". , URL- JS . URL- openURL, JS, .
, displayURL TVContentItem. JS openURL, ( )