tvOS -无法连接到本地主机



我正在测试一些tvOS代码,它在模拟器上工作得很好,但是在运行OS beta 2的Dev Kit上,我收到以下错误:

2015-09-27 11:10:29.797 RWDevCon[272:46267] sssqliteddatabase: Could not open database, resetting: [23,/var/mobile/library/cookies/com.apple.itunesstore.2 .sqlitedb]_CFURLRequestCopyStorageSession弃用2015-09-27 11:10:29.810 RWDevCon[272:46267] html: Setting [1] for Ignore HTTP Cache2015-09-27 11:10:34.886 RWDevCon[272:46267] html: Setting[3]日志级别2015-09-27 11:10:34.887 RWDevCon[277:46267] html: Failed to load launch URL with error: error Domain=NSURLErrorDomain Code=-1004 "Cannot connect to localhost" UserInfo={NSUnderlyingError=0x137d2dee0 {error Domain=kCFErrorDomainCFNetwork Code=-1004 "Could not connect to server."UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1, NSLocalizedDescription=无法连接到服务器。}}, NSErrorFailingURLStringKey=http://localhost:9001/js/application.js, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Cannot connect to localhost}

斯威夫特代码:类AppDelegate: UIResponder, UIApplicationDelegate, TVApplicationControllerDelegate {var window: UIWindow?

var appController: TVApplicationController? /
static let TVBaseURL = "http:/
static let TVBootURL = "(AppDelegate.TVBaseURL)js/application.js" /
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
    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
    /
    appController = TVApplicationController(context: appControllerContext, window: window, delegate: self)
    return true
}

}

**JavaScript/server code:**
App.onLaunch = function(options) {

//1var alert = createAlert("欢迎来到tvOS Programming", "It will be Awesome!");//将第二个参数保留为空字符串navigationDocument.presentModal(警报);}

// 2
var createAlert = function(title, description) {
var alertString = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<alertTemplate>
<title>${title}</title>
<description>${description}</description>
<button><text>OK</text></button>
</alertTemplate>
</document>`
var parser = new DOMParser();
var alertDoc = parser.parseFromString(alertString, "application/xml");
return alertDoc

}

启动服务器:

python -m SimpleHTTPServer 9001

注意:允许任意加载设置为YES

devkit是您网络上的另一台计算机,您不能在kit本身上托管JSTVML服务器。您需要将其托管在外部服务器上(在本例中,您的开发机器就是该外部服务器)。

确保你的devkit和你的开发计算机在同一个网络上。

设置你的js代码通过指定IP地址来访问你的计算机。

示例:http://192.168.1.21:9001/js/application.js(假设192.168.1.21是开发服务器的ip地址,9001是端口)

您应该能够通过首先在浏览器中访问它来测试它(以确保您的开发计算机正确返回.js文件)。

一旦你知道"服务器"正在工作,设置你的javascript访问远程位置。

或者你可以使用Node.js

在你开始之前。您应该查看此文档https://developer.apple.com/library/prerelease/tvos/documentation/General/Conceptual/AppleTV_PG/YourFirstAppleTVApp.html#//apple_ref/doc/uid/TP40015241-CH3-SW1

。你需要什么都行。您可以在此链接下方找到模板项目。https://developer.apple.com/library/prerelease/tvos/samplecode/TVMLCatalog/Introduction/Intro.html

node . js

  1. 拷贝本项目模板桌面。
  2. cmd + space |打开终端
  3. cd/Users/"yourusername"/Desktop/tvOS/TVMLCatalogUsingTVMLTemplates
  4. http-server -p 7575
现在你应该更新AppDelegate.swift文件。
**static let TVBaseURL = "http://localhost:7575/"**

相关内容

  • 没有找到相关文章

最新更新