在swift中配置深层链接? [英] Configure deep links in swift?

查看:29
本文介绍了在swift中配置深层链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个用 swift 编写的应用程序,我想使用深层链接.用户会点击 URL 路径中包含不同信息的内容,例如帖子的 id 或它拥有的点赞数或类似的信息.我知道你把它放在 AppDelegate 中:

So I have an app written in swift that I would like to use deep links for. A user would click on one that in the route of the URL had different pieces of information such as the id of the post or the number of likes it has or something like that. I understand that you put this in the AppDelegate:

func application(application: UIApplication,openURL url: NSURL,sourceApplication sourceApplication: String?,annotation annotation: AnyObject?) -> Bool {
    println(url.host as String!)
    return true
}

然后打印 appname:// 之后的所有内容.但是如何将 url.host 获取到我的视图控制器以解析为我需要的信息.如果 URL 的声明在该函数之外,那么我可以使用这个:

And that prints everything after appname://. But how can I get url.host to my view controller to be parsed into the information I need. If the declaration of URL was outside of that function then I could use this:

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let InfoFromDeepLink = appDelegate.url.host

但是因为它在那个庞大的 Objective-C 函数中,我很无助.你怎么做到这一点?我完全不知所措.我什至不能将函数设置为 return url.host 因为它不允许这样做.这就是我在 Javascript 中会做的事情.如果您也知道 Javascript,也许可以用 Web 开发人员理解的术语来表达,因为我对此很陌生.对于 Swift 开发人员来说,这一定很简单吧?觉得自己好傻.

but since it's inside of that bulky Objective-C function, I'm helpless. How do you do this? I'm completely baffled. I can't even set the function to return url.host because it doesn't allow that. That's what I would do in Javascript. If you also know Javascript maybe put it in terms that a web developer would understand because I'm pretty new to this. This has to be so simple for a Swift developer right? I feel so stupid.

推荐答案

Apple 不再支持 Deep Links.它现在称为通用链接,工作方式略有不同.

Apple no longer supports Deep Links. It is now called Universal Links and works a bit differently.

来源

现在 Apple 不再支持用于深度链接的 URI 方案,开发人员必须实现通用链接才能在 iOS 上正确地进行深度链接.如果您已经在使用 URI 方案,请查看我们关于过渡到通用链接的博客.

Now that Apple no longer supports URI schemes for deep linking, developers must implement Universal Links in order to deep link properly on iOS. If you are already using URI schemes, check out our blog on transitioning to Universal Links.

来自:这里

HERE 是另一篇关于通用链接的文章以及什么他们是.

And HERE is another article on Universal Links and what they are.

这篇关于在swift中配置深层链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆