xcode 如何在 iOS9 中从 Safari 打开 URL 方案?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31361655/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:27:47  来源:igfitidea点击:

How to open URL schemes from Safari in iOS9?

iosxcodeurl-schemeios9xcode7-beta3

提问by kevin

I was able to open apps from safari this way:

我能够通过这种方式从 safari 打开应用程序:

window.location = 'myapp://do/xx';

or open facebook app:

或打开脸书应用程序:

window.location = 'fb://';

But this stopped working in iOS9.

但这在iOS9中停止工作。

How can I open apps using URL schemes in safari?

如何在 safari 中使用 URL 方案打开应用程序?

回答by Malek Belkahla

IOS 9 URL Shchemes Update : iOS 9 introduces LSApplicationQueriesSchemes to allow apps to query if other apps are installed.

IOS 9 URL Shchemes 更新:iOS 9 引入了 LSApplicationQueriesSchemes 以允许应用程序查询是否安装了其他应用程序。

1- If a url scheme is declared and calling canOpenURL(scheme)

1- 如果声明了 url 方案并调用 canOpenURL(scheme)

YES if a installed app supports that URL scheme

YES 如果已安装的应用程序支持该 URL 方案

NO if no app supporting that url

如果没有支持该网址的应用程序,则为否

syslog will show canOpenURL: failed for URL: "urlScheme://" - error: null

syslog 将显示 canOpenURL: failed for URL: "urlScheme://" - 错误:null

2- If a url scheme is not declared and calling canOpenURL(scheme)

2- 如果未声明 url 方案并调用 canOpenURL(scheme)

always return NO

总是返回 NO

syslog will show canOpenURL: failed for URL: "urlScheme://" - error: null

syslog 将显示 canOpenURL: failed for URL: "urlScheme://" - 错误:null

In iOS 9, the developer must add these info.plist LSApplicationQueriesSchemes

在 iOS 9 中,开发者必须添加这些 info.plist LSApplicationQueriesSchemes

<array>
    <string>urlscheme</string>
    <string>urlscheme2</string>
    <string>urlscheme3</string>
    <string>urlscheme4</string>
</array>

50 max. unqiue URL scheme can be declared!

最多 50 个 可以声明unqiue URL scheme!

回答by Helen Woodward

With the general release of ios9 setting window.location to a custom url does launch the app, but only after the user hits open in a popup. I filed a bug with apple about this, and they responded saying that it was intended behavior for launching an app from safari. They said they would look into the issue where if you hit cancel it fails out on future attempts.

随着 ios9 的一般发布,将 window.location 设置为自定义 url 确实会启动应用程序,但只有在用户在弹出窗口中点击打开之后。我向苹果提交了一个关于此的错误,他们回应说这是从 safari 启动应用程序的预期行为。他们说他们会调查这个问题,如果你点击取消,它会在以后的尝试中失败。

回答by eschanet

With iOS9, Apple is changing a few things concerning URL schemes. Hereis an article about those changes.

在 iOS9 中,Apple 正在更改有关 URL 方案的一些内容。是一篇关于这些变化的文章。

Basically, you now haveto register all URL schemes that are supported by your app in your .plist file.

基本上,您现在必须在 .plist 文件中注册您的应用程序支持的所有 URL 方案。

回答by Pavel Sadchenko

Just assign a desired address to the hrefproperty, instead of trying to replace the whole window.locationobject:

只需为该href属性分配一个所需的地址,而不是尝试替换整个window.location对象:

window.location.href = 'myapp://do/xx';

window.location.href = 'myapp://do/xx';

It works for me on iOS 9.0.2, but now safari shows a confirmation dialog to ensure а user really wants open your link in the app.

它在 iOS 9.0.2 上对我有用,但现在 safari 显示一个确认对话框,以确保用户确实想要在应用程序中打开您的链接。

回答by swiftBoy

this is how I have revised my Facebook/Google Login integration to get it work on latest update. which now user Safari web view.

这就是我修改我的 Facebook/Google 登录集成以使其适用于最新更新的方式。现在用户 Safari 网页视图。

<key>LSApplicationQueriesSchemes</key>
  <array>
      <string>fbapi</string>
      <string>fb-messenger-api</string>
      <string>fbauth2</string>
      <string>fbshareextension</string>
      <string>com.googleusercontent.apps.39373238582-opjuqokmar2i5t3sdk2vs5sifer4moen</string>
      <string>com-google-gidconsent-google</string>
      <string>com-google-gidconsent-youtube</string>
      <string>com-google-gidconsent</string>
      <string>com.google.gppconsent.2.4.1</string>
      <string>com.google.gppconsent.2.4.0</string>
      <string>googlechrome</string>
      <string>googlechrome-x-callback</string>
  </array>
<key>LSApplicationQueriesSchemes</key>
  <array>
      <string>fbapi</string>
      <string>fb-messenger-api</string>
      <string>fbauth2</string>
      <string>fbshareextension</string>
      <string>com.googleusercontent.apps.39373238582-opjuqokmar2i5t3sdk2vs5sifer4moen</string>
      <string>com-google-gidconsent-google</string>
      <string>com-google-gidconsent-youtube</string>
      <string>com-google-gidconsent</string>
      <string>com.google.gppconsent.2.4.1</string>
      <string>com.google.gppconsent.2.4.0</string>
      <string>googlechrome</string>
      <string>googlechrome-x-callback</string>
  </array>