Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tvOS - Cannot connect to localhost

I am testing some tvOS code and it works great on the Simulator however on the Dev Kit running OS beta 2 I am receiving the following error:

2015-09-27 11:10:29.797 RWDevCon[272:46267] SSSQLiteDatabase: Could not open database, resetting: [23, /var/mobile/Library/Cookies/com.apple.itunesstored.2.sqlitedb] _CFURLRequestCopyStorageSession deprecated 2015-09-27 11:10:29.810 RWDevCon[272:46267] ITML: Setting [1] for Ignore HTTP Cache 2015-09-27 11:10:34.886 RWDevCon[272:46267] ITML: Setting [3] log level 2015-09-27 11:10:34.887 RWDevCon[272:46267] ITML : 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 the server." UserInfo={ _kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1, NSLocalizedDescription=Could not connect to the server.}}, NSErrorFailingURLStringKey=http://localhost:9001/js/application.js, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Cannot connect to localhost}

Swift Code: class 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!"); // leaving 2nd parameter with an empty string 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

}

Starting the Server:

python -m SimpleHTTPServer 9001

NB: Allow Arbitary Loads is set to YES

like image 637
decipher21 Avatar asked Oct 27 '25 05:10

decipher21


2 Answers

The devkit is another computer on your network, and you can't host the JSTVML server on the kit itself. You need to host it on an external server (in this case your development machine is that external server).

Make sure your devkit and your development computer are on the same network.

Set up your js code to access your computer by specifying the IP address.

Ex: http://192.168.1.21:9001/js/application.js (pretending that 192.168.1.21 is the ip address of your development server and 9001 is the port.)

You should be able to test this out by accessing it in your browser first (to make sure you're development computer is returning the .js file correctly).

Once you know the 'server' is working, setup your javascript to access that remote location.

Hope this helps.

like image 68
Jason Jarrett Avatar answered Oct 28 '25 18:10

Jason Jarrett


Or You can user Node.js

Before you start. you should check this documentation https://developer.apple.com/library/prerelease/tvos/documentation/General/Conceptual/AppleTV_PG/YourFirstAppleTVApp.html#//apple_ref/doc/uid/TP40015241-CH3-SW1

Second. Whatever you need. You can find template project below this link. https://developer.apple.com/library/prerelease/tvos/samplecode/TVMLCatalog/Introduction/Intro.html

Node.js

  1. Copy template desktop of this project.
  2. cmd + space | open terminal
  3. sudo npm install http-server -g
  4. cd /Users/"yourusername"/Desktop/tvOS/TVMLCatalogUsingTVMLTemplates
  5. http-server -p 7575

ok Now yo should update AppDelegate.swift file.

**static let TVBaseURL = "http://localhost:7575/"**
like image 32
Durul Dalkanat Avatar answered Oct 28 '25 19:10

Durul Dalkanat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!