turbolinks / turbolinks-ios

Native iOS adapter for building hybrid apps with Turbolinks 5
MIT License
881 stars 92 forks source link

Unable to load page #42

Closed bryanvero closed 7 years ago

bryanvero commented 8 years ago

I am trying to add Turbolinks-ios to an existing ios project. I have created a new view controller that is embedded in a navigation controller. I have added the code below and it does load the web display and begin spinning, but it does not load the contents of the webpage. I have confirmed that going to Safari in the simulator does load the page without issue.

import UIKit
import Turbolinks

class SignInView: UIViewController {
    var window: UIWindow?
    var session = Session()

    override func viewDidAppear(animated: Bool) {
        session.delegate = self
        visit(NSURL(string: "http://192.168.1.8:3000")!)
    }

    func visit(URL: NSURL) {
        let visitableViewController = VisitableViewController(URL: URL)
        navigationController!.pushViewController(visitableViewController, animated: true)
        session.visit(visitableViewController)
    }
}

extension SignInView: SessionDelegate {
    func session(session: Session, didProposeVisitToURL URL: NSURL, withAction action: Action) {
        visit(URL)
    }

    func session(session: Session, didFailRequestForVisitable visitable: Visitable, withError error: NSError) {
        let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .Alert)
        alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
        navigationController!.presentViewController(alert, animated: true, completion: nil)
    }
}

The page being loaded is just a simple page with a few assets. I also tried to test this against https://google.com and it just spins the same way.

joemasilotti commented 8 years ago

The website needs to be running Turbolinks v5 installed for the iOS framework to work. Google does not have the JavaScript library.

bryanvero commented 8 years ago

I have installed Turbolinks in my app and confirmed the JS is loaded, but it still hangs in my simulator. I am using http://localhost:3000, and have added the SSL cert to my keychain, and confirmed it loads properly in Safari in the simulator.

When I load my app, the webview just spins. How can I debug what is going on?

ericgross commented 8 years ago

It eventually started working, just had to fiddle for a while.

sstephenson commented 8 years ago

@bryanvero Things to double-check:

  1. Make sure you’re using Turbolinks 5. Older versions won’t work.
  2. You won’t need an SSL certificate to access http://localhost:3000, but you will need to configure App Transport Security to allow access to unencrypted HTTP. See the Quick Start Guide for instructions.
jonaldomo commented 8 years ago

FWIW: I started a brand new rails project and brand new IOS project to check out the functionality. I ran into the spinner on a brand new rails app with the URL pointing to localhost:3000. The default index page "Yay you are rails" does not have turbolinks included. After I pointed / to something else like /posts, it worked.