我使用了一个教程来实现应用程序委托(delegate)中的方法,以从 safari 的 HTML 按钮打开特定的 View Controller 。我的应用程序委托(delegate)如下所示:
func application(_ app: UIApplication, open URL: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print("url \(url)")
print("url host :\(url.host!)")
print("url path :\(url.path)")
let urlPath : String = (url.path as String?)!
let urlHost : String = (url.host as String?)!
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
if(urlHost != "mywebsite.ir")
{
print("Host is not correct")
return false
}
if(urlPath == "/index"){
let innerPage: ViewController = mainStoryboard.instantiateViewController(withIdentifier: "HomeViewController") as! ViewController
self.window?.rootViewController = innerPage
}
self.window?.makeKeyAndVisible()
return true
}
我的 HTML 按钮引用是:
<a href= "myapp://mywebsite.ir/index">open app</a>
但是当我的应用程序主页打开时,导航栏消失了,用户被卡住并且无法访问菜单按钮或后退按钮(如果是内部 View Controller )。
深层链接前后主视图 Controller 的屏幕截图:
最佳答案
请按如下方式更新您的代码..您应该将导航 Controller 作为窗口 Root View Controller ..
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print("url \(url)")
print("url host :\(url.host!)")
print("url path :\(url.path)")
let urlPath : String = (url.path as String?)!
let urlHost : String = (url.host as String?)!
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
if(urlHost != "mywebsite.ir")
{
print("Host is not correct")
return false
}
if(urlPath == "/index"){
let innerPage: ViewController = mainStoryboard.instantiateViewController(withIdentifier: "HomeViewController") as! ViewController
let nav = UINavigationController.init(rootViewController: innerPage)
self.window?.rootViewController = nav
}
self.window?.makeKeyAndVisible()
return true
关于ios - 通过深层链接打开 View Controller 时导航栏消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50117172/