我已經從Apple下載了TVMLCatalog應用程序。代碼分爲兩部分。您可以在Apple TV上代替外部服務器託管TVJS文件嗎?
- 客戶 - 這個持有TVML和TVJS文件
- TVMLCatalog項目 - 這是基本的Xcode項目,設置了TVML/TVJS
我試圖主機客戶端 TVJS文件與TVMLCatalog項目相同。
我已經改變了的AppDelegate didFinishLaunching如下:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds)
/*
Create the TVApplicationControllerContext for this application
and set the properties that will be passed to the `App.onLaunch` function
in JavaScript.
*/
let appControllerContext = TVApplicationControllerContext()
/*
The JavaScript URL is used to create the JavaScript context for your
TVMLKit application. Although it is possible to separate your JavaScript
into separate files, to help reduce the launch time of your application
we recommend creating minified and compressed version of this resource.
This will allow for the resource to be retrieved and UI presented to
the user quickly.
*/
TVBootURL = NSBundle.mainBundle().pathForResource("application", ofType: "js")!
TVBaseURL = TVBootURL.stringByReplacingOccurrencesOfString("application.js", withString: "")
if let javaScriptURL = NSURL(string: TVBootURL) {
appControllerContext.javaScriptApplicationURL = javaScriptURL
}
appControllerContext.launchOptions["BASEURL"] = TVBaseURL
if let launchOptions = launchOptions as? [String: AnyObject] {
for (kind, value) in launchOptions {
appControllerContext.launchOptions[kind] = value
}
}
appController = TVApplicationController(context: appControllerContext, window: window, delegate: self)
return true
}
這裏是演示如何我已經導入了客戶截圖: Xcode Screenshot
當我運行項目(只我在AppleTV模擬器屏幕上顯示以下消息:
啓動應用程序時出錯 - 操作無法完成。 (TVMLKitErrorDomain錯誤3.)
我可以像這樣從本地加載TVJS文件嗎?
在我看來,以'if let launchOptions..'開頭的5行是不需要的 - 或者至少,它沒有它們就可以爲我工作。 – coco
完全不起作用。這是什麼版本 – Coldstar
@Coldstar更新了Swift 3。 – shirefriendship