iOS 通用链接未在应用内打开
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32751225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS Universal Links are not opening in-app
提问by Legolas
So I followed this tutorial exactly and use the same values as the ones provided: https://blog.branch.io/how-to-setup-universal-links-to-deep-link-on-apple-ios-9
所以我完全遵循本教程并使用与提供的值相同的值:https: //blog.branch.io/how-to-setup-universal-links-to-deep-link-on-apple-ios-9
The Apple Association file is also ready in the link directory:WEB_PAGE:PORT_NUMBER/apple-app-site-association
苹果协会文件也在链接目录中准备好了:WEB_PAGE:PORT_NUMBER/apple-app-site-association
Everything seems to be set up on this side.
一切似乎都安排在这一边。
I've added the entitlements, updated the provisioning profile, and everything's set up.
我已经添加了权利,更新了配置文件,一切都设置好了。
When I run the app on my device, and open the link http://WEB_PAGE:PORT_NUMBER
, this always opens Safari.
当我在我的设备上运行该应用程序并打开链接时http://WEB_PAGE:PORT_NUMBER
,这始终会打开 Safari。
I even have breakpoints in the following method:
我什至在以下方法中有断点:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler
But zilch.
但是齐尔奇。
Has anyone perfected this? Is there something I'm missing?
有没有人完善这个?有什么我想念的吗?
回答by st.derrick
There are a few possible issues.
有几个可能的问题。
Try pasting your domain into this link validator and make sure there are no issues: https://limitless-sierra-4673.herokuapp.com/(credit to ShortStuffSushi -- see repo)
iOS logs an error message in the system logs if you don't have TLS set up properly on the domain specified in your entitlements. It's buried in the OS logs, not application logs. The error message will look like
Sep 21 14:27:01 Derricks-iPhone swcd[2044] <Notice>: 2015-09-21 02:27:01.878907 PM [SWC] ### Rejecting URL 'https://examplecustomdomain.com/apple-app-site-association' for auth method 'NSURLAuthenticationMethodServerTrust': -6754/0xFFFFE59E kAuthenticationErr
. Error message pulled from here, quick (incomplete) instructions on using CloudFlare for TLS here.In my personal testing, clicking/typing in a link in Safari has never once opened the app directly. Clicking from other apps (iMessage, Mail, Slack, etc.) hasworked. Others have reported that clicking links in Google search results have opened the app directly.
Note that if a Universal Link succeeds in opening your app and then you click through to Safari (by tapping your site in the top right corner of the nav bar in app), then iOS stops opening the app when you visit that URL. Then in Safari, you can pull down to reveal a banner at the top of the page with "Open". I wasted a lot of time on this.Note that clicking through to the site => disabling UL seems path specific, based on the paths you specify in the apple-app-site-assocation file. So if you have separate routes,
yoursite.com/a/*
andyoursite.com/b/*
, if you clickyoursite.com/a/*
and it opens your app directly, you then have the option in the top right corner of the app to click through toyoursite.com/a/*
. If you do that, subsequent visits toyoursite.com/a/*
will open in browser, not app. However,yoursite.com/b/*
should be unaffected and still open your app directly.
尝试将您的域粘贴到此链接验证器中并确保没有问题:https: //limitless-sierra-4673.herokuapp.com/(归功于 ShortStuffSushi - 请参阅repo)
如果您没有在权利中指定的域上正确设置 TLS,iOS 会在系统日志中记录一条错误消息。它隐藏在操作系统日志中,而不是应用程序日志中。错误消息将如下所示
Sep 21 14:27:01 Derricks-iPhone swcd[2044] <Notice>: 2015-09-21 02:27:01.878907 PM [SWC] ### Rejecting URL 'https://examplecustomdomain.com/apple-app-site-association' for auth method 'NSURLAuthenticationMethodServerTrust': -6754/0xFFFFE59E kAuthenticationErr
。错误消息来自拉到这里,使用的CloudFlare的快速TLS(不完全)的说明这里。在我的个人测试中,在 Safari 中单击/输入链接从未直接打开过应用程序。从其他应用程序(iMessage、Mail、Slack 等)点击已经奏效。其他人报告说,点击谷歌搜索结果中的链接直接打开了该应用程序。
请注意,如果通用链接成功打开您的应用程序,然后您点击进入 Safari(通过点击应用程序导航栏右上角的您的站点),那么当您访问该 URL 时,iOS 将停止打开该应用程序。然后在 Safari 中,您可以下拉以在页面顶部显示带有“打开”的横幅。我在这上面浪费了很多时间。请注意,根据您在 apple-app-site-association 文件中指定的路径,单击站点 => 禁用 UL 似乎是特定于路径的。因此,如果您有单独的路线,
yoursite.com/a/*
并且yoursite.com/b/*
,如果您单击yoursite.com/a/*
并直接打开您的应用程序,则您可以在应用程序的右上角选择单击以到达yoursite.com/a/*
。如果你这样做,后续访问yoursite.com/a/*
将在浏览器中打开,而不是应用程序。但是,yoursite.com/b/*
应该不受影响并且仍然直接打开您的应用程序。
Let me know if you discover what the issue is. I'm personally very curious about how Universal Links work and what edge cases exist. Good luck.
如果您发现问题所在,请告诉我。我个人对通用链接的工作方式以及存在哪些边缘情况非常好奇。祝你好运。
回答by DFedor
There are a lot of ways this can go wrong. Two points caused me trouble:
有很多方法可能会出错。有两点给我带来了麻烦:
In Xcode, when you add the Associated Domains entitlement, each entry needs to start with
applinks:
and then your domain name. E.g.applinks:www.apple.com
.Though Xcode created an entitlements file for me, it did not include in my build: I had to click that box manually.
在 Xcode 中,当您添加 Associated Domains 权利时,每个条目都需要以
applinks:
您的域名开头。例如applinks:www.apple.com
。尽管 Xcode 为我创建了一个权利文件,但它并没有包含在我的构建中:我必须手动单击该框。
And yes, after doing that, it wasn't necessary to sign the apple-app-site-association
file: it is just plain text, and it works, as long as it's served over HTTPS. (You'll still need to sign it if you're supporting iOS 8, though.)
是的,这样做之后,就没有必要对apple-app-site-association
文件进行签名了:它只是纯文本,只要通过 HTTPS 提供服务,它就可以工作。(不过,如果你支持 iOS 8,你仍然需要签名。)
回答by Curtis Brian Halbrook
There is apparently an error in the documentation for making the association file for Universal Links.
为 Universal Links 制作关联文件的文档中显然有错误。
Where it says:
它在哪里说:
The value of the appID key is the app's team ID and the bundle ID
appID 键的值是应用的团队 ID 和包 ID
it should say
它应该说
The value of the appID key is the app's Prefix and the bundle ID
appID 键的值是应用程序的前缀和包 ID
For most apps, it seems that the Team ID and app prefixes are the same, but if your app has been in the store for many years, these values can be different.
对于大多数应用程序,Team ID 和应用程序前缀似乎是相同的,但如果您的应用程序已在商店中存在多年,则这些值可能会有所不同。
To find this value, open the Member Center on https://developer.apple.comand look at "Certificates, Identifiers & Profiles", click "Identifiers", then "App IDs" in the table under "Identifiers". Find your app, and use the Prefix value and Bundle ID there to create your AppID for the association file.
要找到此值,请在https://developer.apple.com上打开会员中心并查看“证书、标识符和配置文件”,单击“标识符”,然后单击“标识符”下表格中的“应用程序 ID”。找到您的应用程序,并使用其中的 Prefix 值和 Bundle ID 为关联文件创建您的 AppID。
回答by mpoisot
To help debugging this issue, search for "swcd" in your device's console output when installing your app to see if registering your universal link worked or failed.
为了帮助调试此问题,请在安装应用程序时在设备的控制台输出中搜索“swcd”,以查看注册通用链接是否有效。
- Use an actual device, not the simulator.
- Delete the app from you device.
- Connect the device to your computer, and view the device's console output in xcode. (window -> devices -> [your device] -> open console). Keep this window open.
- Install your app and let it launch.
- Filter the console output to "swcd". If it's sucessful you will see something like the folowing screenshot. If it fails you'll see something else. If you don't see anything then you messed something fundamental like adding the Associated Domains entitlement.
- 使用实际设备,而不是模拟器。
- 从您的设备中删除该应用程序。
- 将设备连接到您的计算机,并在 xcode 中查看设备的控制台输出。(窗口 -> 设备 -> [你的设备] -> 打开控制台)。保持这个窗口打开。
- 安装您的应用程序并让它启动。
- 将控制台输出过滤为“swcd”。如果成功,您将看到类似于以下屏幕截图的内容。如果它失败了,你会看到别的东西。如果你没有看到任何东西,那么你就搞砸了一些基本的东西,比如添加关联域权利。
回答by Praveen
St.derrick's Answeris informative.
St.derrick 的回答内容丰富。
But to enable universal links again to open in app instead of safari we need to do the following thing.
但是要再次启用通用链接以在应用程序中打开而不是在 safari 中打开,我们需要执行以下操作。
- Long press on Universal link in Mail or iMessage, then you will see options whether to open in safari or in App.
- 在邮件或 iMessage 中长按通用链接,然后您将看到是在 safari 中还是在 App 中打开的选项。
回答by Devy
To validate apple-app-site-association
on the server side, you can
use Apple's official validator.
要apple-app-site-association
在服务器端进行验证,您可以使用 Apple 的官方验证器。
https://search.developer.apple.com/appsearch-validation-tool/
https://search.developer.apple.com/appsearch-validation-tool/
回答by Nikhil Mathew
Quick steps to check whether you have implemented Universal Link correctly.
检查您是否正确实施通用链接的快速步骤。
Tap and hold on the link that you expect to launch the app. You should see a "Open in [your app name]" in the Context Menu.
Open Notes app, type the link you expect to open the app. Tap Done. The link will turn yellow and tapping on the link should open your app, and not Safari.
If the link http://yourDomain.comis not launching the app, try http://yourDomain.com/yourFolder/
In Safari, If the Context Menu shows "Open in [your app name]" in safari, but tapping the link opens the link in safari itself instead of launching the app,
a. Try pulling down on the safari page that opened when the link was clicked like the way you 'pull to refresh'. A banner should appear that can open your app. Tap the banner to open the app, close the app by pressing home button, get back to safari and try launching the app by tapping the link again. This time on, the app should get launched because tapping the banner should have saved the preference to open the link in app.
b. If the app still don't get launched after the step a., try mailing the link to a webmail such as gmail and open the webmail site in safari and try clicking the link. If this works, you may have been trying to launch the app from the same domain as the link. From what I have seen, launching the app from the same domain mostly fails. Probably safari wont care to check whether the destination url is a universal link, when the link is into the same domain that user is on. So try to launch the app from another domain.
点击并按住您希望启动应用程序的链接。您应该在上下文菜单中看到“在 [您的应用程序名称] 中打开”。
打开 Notes 应用程序,键入您希望打开该应用程序的链接。点击完成。该链接将变为黄色,点击该链接应打开您的应用程序,而不是 Safari。
如果链接http://yourDomain.com没有启动应用程序,请尝试http://yourDomain.com/yourFolder/
在 Safari 中,如果上下文菜单在 safari 中显示“在 [您的应用程序名称] 中打开”,但点击链接会在 safari 本身中打开链接而不是启动应用程序,
一种。尝试在单击链接时打开的 safari 页面下拉,就像您“拉动刷新”的方式一样。应该会出现一个可以打开您的应用程序的横幅。点击横幅以打开应用程序,按主页按钮关闭应用程序,返回 safari 并再次点击链接尝试启动应用程序。这一次,应用程序应该会启动,因为点击横幅应该保存了在应用程序中打开链接的首选项。
湾 如果应用程序在步骤 a. 后仍未启动,请尝试将链接邮寄到网络邮件(例如 gmail)并在 safari 中打开网络邮件站点并尝试单击该链接。如果这有效,您可能一直在尝试从与链接相同的域启动应用程序。据我所知,从同一个域启动应用程序大多失败。当链接进入用户所在的同一个域时,safari 可能不会关心检查目标 url 是否是通用链接。所以尝试从另一个域启动应用程序。
回答by tidbeck
I realized that be problem for me was that links to the root directory a (eg. http://example.com/
) did not open my app but if I added a path (eg. http://example.com/mypath
) it worked. Adding "/"
to the paths list sovled it:
我意识到对我来说问题是指向根目录 a(例如http://example.com/
)的链接没有打开我的应用程序,但是如果我添加了一个路径(例如http://example.com/mypath
),它就可以工作。添加"/"
到路径列表解决了它:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "TEAM_ID.BundleIdentifier",
"paths": [ "*", "/" ]
}
]
}
}
As answered by slutsker in thisApple Developer Forums thread.
正如 slutsker 在这个Apple Developer Forums thread 中回答的那样。
回答by Kyle Truscott
It's also super important to increment the project version or build number after integrating universal links. Even if you delete/reinstall, iOS won't pickup the links unless you bump the version.
在集成通用链接后增加项目版本或内部版本号也非常重要。即使您删除/重新安装,除非您修改版本,否则 iOS 也不会提取链接。
回答by guido
Universal Links will not work if you paste the link into the browser URL field.
Universal Links workwith a user driven
<a href="...">
element click across domains. Example: if there is a Universal Link on google.com pointing to bnc.lt, it will open the app.Universal Links will not workwith a user driven
<a href="...">
element click on the same domain. Example: if there is a Universal Link on google.com pointing to a different Universal Link on google.com, it will not open the app.Universal Links cannot be triggered via Javascript (in window.onload or via a .click() call on an
<a>
element), unless it is part of a user action.
如果您将链接粘贴到浏览器 URL 字段中,通用链接将不起作用。
通用链接与用户驱动的跨域元素点击一起工作。示例:如果 google.com 上有指向 bnc.lt 的通用链接,它将打开该应用程序。
<a href="...">
通用链接不适用于同一域上的用户驱动
<a href="...">
元素点击。示例:如果 google.com 上的通用链接指向 google.com 上的其他通用链接,则不会打开该应用。通用链接不能通过 Javascript 触发(在 window.onload 中或通过对
<a>
元素的 .click() 调用),除非它是用户操作的一部分。
来源:https: //dev.branch.io/getting-started/universal-app-links/support/ios/#appsbrowsers-that-support-universal-links
The 3rd bullet cost me about a day to figure out.
第三颗子弹花了我大约一天的时间来弄清楚。