我正在测试一些 tvOS 代码,它在模拟器上运行良好,但是在运行 OS beta 2 的开发套件上,我收到以下错误:
2015-09-27 11:10:29.797 RWDevCon [272:46267] SSSQLiteDatabase:无法打开数据库,重置:[23,/var/mobile/Library/Cookies/com.apple.itunesstored.2.sqlitedb] _CFURLRequestCopyStorageSession 已于 2015 年弃用-09-27 11:10:29.810 RWDevCon [272:46267] ITML:设置 [1] 以忽略 HTTP 缓存 2015-09-27 11:10:34.886 RWDevCon [272:46267] ITML:设置 [3] 日志级别 2015 -09-27 11:10:34.887 RWDevCon[272:46267] ITML:无法加载启动 URL 并出现错误:错误域 = NSURLErrorDomain 代码 = -1004 “无法连接到本地主机” UserInfo = {NSUnderlyingError = 0x137d2dee0 {错误域 = kCFErrorDomainCFNetwork Code=-1004 “无法连接到服务器。” UserInfo={ _kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1, NSLocalizedDescription=无法连接到服务器。}}, NSErrorFailingURLStringKey=http://localhost:9001/js/application.js , _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=无法连接到 localhost}
Swift 代码: 类 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) {
// 1 var alert = createAlert("Welcome to tvOS Programming", "It will be Awesome!"); // 将第二个参数留为空字符串 navigationDocument.presentModal(alert); }
// 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