ios 当我尝试从网站启动我的应用程序时出现“Safari 无法打开页面,因为地址无效”消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39565353/
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
"Safari cannot open the page because the address is invalid" message appears when I try to launch my app from a website
提问by Vignesh Kumar
Device : iPhone 5 / iOS 9.3
设备:iPhone 5 / iOS 9.3
I have an iOS appwhich I need to launch from a website. I was able to do it via custom URL scheme.
我有一个iOS 应用程序,需要从网站启动。我能够通过自定义 URL 方案来做到这一点。
When I click the "Open App" button in the website, an alert dialog appears that says "Safari wants to open MyApp" with OK & Cancel buttons.
当我单击网站上的“打开应用程序”按钮时,会出现一个警告对话框,显示“ Safari 想要打开我的应用程序”,并带有“确定”和“取消”按钮。
Clicking OK: everything is just fine. The app gets launched from the website perfectly.
单击确定:一切都很好。该应用程序完美地从网站启动。
Clicking Cancel: First time, it just dismisses preventing the app being launched, which is correct.
单击Cancel:第一次,它只是取消阻止启动应用程序,这是正确的。
When I click on the "Open App" button once again from the website, I expect the same "Safari wants to launch MyApp" alert dialog to appear once again, which is not happening.
当我再次从网站上单击“打开应用程序”按钮时,我希望再次出现相同的“Safari 想要启动 MyApp”警报对话框,但这种情况并没有发生。
Instead, it shows a dialog that says "Cannot Open Page - Safari cannot open the page because the address is invalid" with an OK button.
相反,它会显示一个对话框,上面写着“无法打开页面 - Safari 无法打开页面,因为地址无效”和一个确定按钮。
My assumption was, every time when you click on that link in the website (that can launch the app via custom url scheme), I should be prompted with "safari wants to open MyApp" alert dialog all the time.
我的假设是,每次当您单击网站中的该链接(可以通过自定义 url 方案启动应用程序)时,我都应该一直提示“safari 想要打开 MyApp”警报对话框。
What am I missing here ? Appreciate your help in advance.
我在这里错过了什么?提前感谢您的帮助。
回答by Honey
It's a known behavior.
这是众所周知的行为。
If you tap on facebook://feeds
and open it then Safari won't blacklist the facebook
scheme for that Safari tab. You would be allowed to open facebook://profile
, facebook://feeds
, facebook://settings
, etc. on that tab
如果您点击facebook://feeds
并打开它,则 Safari 不会facebook
将该Safari 选项卡的方案列入黑名单。你将被允许打开facebook://profile
,facebook://feeds
,facebook://settings
,等该选项卡上
However if you click on 'Cancel' then you're no longer able to able any url with that scheme for that tab onlyie you won't be able to open facebook://profile
, because it's been blacklisted for that tab.
但是,如果您单击“取消”,那么您将无法再使用该方案的任何网址访问该选项卡,即您将无法打开facebook://profile
,因为它已被列入该选项卡的黑名单。
What should you do?
你该怎么办?
Open a new tab and try again. It would no longer be blacklisted for that tab.
打开一个新选项卡并重试。它将不再被列入该选项卡的黑名单。
It would have been much better though if Apple prompted its user with options like:
不过,如果 Apple 提示其用户使用以下选项,情况会好得多:
Deny once. Deny Always. Allow Always
拒绝一次。始终拒绝。始终允许
But I'm guessing if they did that then they'd have to provide alternate ways for the user to customize behavior per host/scheme. Obviously Apple doesn't want to allow that.
但是我猜如果他们这样做了,那么他们就必须为用户提供替代方法来自定义每个主机/方案的行为。显然,Apple 不想允许这样做。
回答by Thanh An Nguy?n
I met the same problem when using Google Tag Manager in my code. Try the javascript event for opening the app instead of using the href of the tag a.
在我的代码中使用 Google 标签管理器时遇到了同样的问题。尝试使用 javascript 事件打开应用程序,而不是使用标签 a 的 href。
回答by Talib Shabbir Hussain
I was getting a similar error, fixed it by allowing "Installing App" in restriction(Settings->General->Restriction), enable the toggle button. It is by default enabled but I restricted it in past by disabling the toggle button.
我遇到了类似的错误,通过在限制(设置->常规->限制)中允许“安装应用程序”来修复它,启用切换按钮。它默认启用,但我过去通过禁用切换按钮来限制它。
Hope this helps anyone.
希望这可以帮助任何人。
回答by Cat
I just fixed the same problem on an iphone. Go to settings> General> Restrictions> Safari. Make sure it is "allowed" or turned on (swipe to green). Exit out of settings and retry. It should work.
我刚刚在 iPhone 上解决了同样的问题。转到设置> 常规> 限制> Safari。确保它被“允许”或打开(滑动到绿色)。退出设置并重试。它应该工作。