如何在iOS9中从Safari打开URLscheme?
我可以这样从safari打开应用程序:
window.location = 'myapp://do/xx';
或打开Facebook应用程序:
window.location = 'fb://';
但是这停止在iOS9的工作。
如何在safari中使用URLscheme打开应用程序?
IOS 9 URL Shchemes更新:iOS 9引入了LSApplicationQueriesSchemes,以允许应用程序查询是否安装了其他应用程序。
1-如果声明一个urlscheme并调用canOpenURL(scheme)
如果安装的应用程序支持该URLscheme,则为YES
如果没有支持该url的应用,则为NO
系统日志将显示canOpenURL:URL失败:“urlScheme://” – 错误:null
2-如果没有声明urlscheme并调用canOpenURL(scheme)
总是返回NO
系统日志将显示canOpenURL:URL失败:“urlScheme://” – 错误:null
在iOS 9中,开发人员必须添加这些info.plist LSApplicationQueriesSchemes
<array> <string>urlscheme</string> <string>urlscheme2</string> <string>urlscheme3</string> <string>urlscheme4</string> </array>
最多50 unqiueurlscheme可以申报!
在iOS9中,苹果正在改变一些关于URLscheme的东西。 这是一篇关于这些变化的文章。
基本上,您现在必须在您的.plist文件中注册您的应用程序支持的所有URLscheme。
随着ios9设置window.location的一般发布设置为自定义url,启动应用程序,但只有在用户打开popup窗口后。 我提出了一个关于这个苹果的错误,他们回应说,这是从Safari浏览器启动应用程序的预期行为。 他们表示,他们会研究这个问题,如果你点击取消,未来的尝试将失败。
只需将所需的地址分配给href
属性,而不是试图replace整个window.location
对象:
window.location.href = 'myapp://do/xx';
它适用于我在iOS 9.0.2,但现在Safari浏览器显示确认对话框,以确保用户真的想在应用程序中打开您的链接。
这是我如何修改我的Facebook /谷歌login集成,以使其在最新的更新工作。 现在用户在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>