创建一个链接,你的应用程序通过其他应用推出
问题描述:
现在,我完全知道你可以使用这样的事情从另一个移动应用(未测试)推出的Instagram:创建一个链接,你的应用程序通过其他应用推出
var instagramHooks = "instagram://user?username=johndoe"
var instagramUrl = NSURL(string: instagramHooks)
if UIApplication.sharedApplication().canOpenURL(instagramUrl!) {
UIApplication.sharedApplication().openURL(instagramUrl!)
}
else {
//redirect to safari because the user doesn't have Instagram
UIApplication.sharedApplication().openURL(NSURL(string: "http://instagram.com/")!)
}
我是什么感兴趣的是创建一个url,将您直接带到移动应用程序中的某个页面。 instagram://user?username=johndoe
在启动应用程序后将用户带到johndoe
的配置文件页面。如何创建类似于此的链接?
答
我会推荐使用Compass来实现这一点。
有了指南针,你可以做这样的
Navigator.handle = { [weak self] location in
let arguments = location.arguments
let rootController = self?.window.rootViewController as? UINavigationController
switch location.path {
case "profile:{username}":
let profileController = ProfileController(title: arguments["username"])
rootController?.pushViewController(profileController, animated: true)
case "login:{username}":
let loginController = LoginController(title: arguments["username"])
rootController?.pushViewController(loginController, animated: true)
case "logout":
self?.clearLoginSession()
self?.switchToLoginScreen()
default:
break
}
}