我一直在玩 Turbolinks 5,但在单击我的应用程序中的链接后,我似乎无法让它正确访问新页面。该应用程序加载新视图,就像它在 webview 中被替换一样,并且不会像我期望的那样将新的视图控制器推送到堆栈上。好像它没有执行Turblonks.visit
我正在运行启用了 Turbolinks 5 的 rails 5.1 应用程序。我的链接如下所示:
<%= link_to 'View', test_path(test_id), class: 'btn btn-secondary btn-block marginTop_short' %>
如您所见,此链接没有什么特别之处!
我的 iOS 应用程序代码非常基本:
import UIKit
import Turbolinks
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var navigationController = UINavigationController()
var session = Session()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window?.rootViewController = navigationController
startApplication()
return true
}
func startApplication() {
session.delegate = self
visit(URL: NSURL(string: "http://localhost:3000")!)
}
func visit(URL: NSURL) {
print("visiting", URL)
let visitableViewController = VisitableViewController(url: URL as URL)
navigationController.pushViewController(visitableViewController, animated: true)
session.visit(visitableViewController)
}
}
extension AppDelegate: SessionDelegate {
func session(_ session: Session, didProposeVisitToURL URL: URL, withAction action: Action) {
print("trying to visit", URL)
print("action", action)
visit(URL: URL as NSURL)
}
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.present(alert, animated: true, completion: nil)
}
}
当我单击链接时,它不会触发func session(_ session: Session, didProposeVisitToURL URL: URL, withAction action: Action)
回调。
也许更准确地说,当点击链接时,webview 没有响应或创建访问建议?
我错过了什么?任何帮助,将不胜感激。
让我知道是否需要更多细节或澄清。