繁体   English   中英

Zattoo App网址方案

[英]Zattoo App url scheme

我需要从我的应用程序中打开Zattoo应用程序(在按钮单击事件上)

我所做的是

let url:NSURL? = NSURL(string: "zattoo://")
if UIApplication.sharedApplication().canOpenURL(url!) {
       UIApplication.sharedApplication().openURL(url!)

    } else {

        print("App not installed")

        //redirect to safari because the user doesn't have Zattoo App installed

        UIApplication.sharedApplication().openURL(NSURL(string: "https://itunes.apple.com/de/app/zattoo-tv-app-sports-news/id423779936?l=en")!)
   }

canOpenURL()总是返回false(即使我的设备上安装了Zattoo应用程序),因此else中的代码也总是执行。

但是,如果删除检查并仅执行

 let url:NSURL? = NSURL(string: "zattoo://")

 UIApplication.sharedApplication().openURL(url!)

它完美地打开了Zattoo应用程序。 奇怪!

我做错了什么?

在iOS9中,您应该注册要用于打开其他应用程序的自定义方案。 它应该被存储为字符串(定制方案)与阵列LSApplicationQueriesSchemes在关键Info.plist文件。 从官方文档( https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW14 ):

LSApplicationQueriesSchemes(Array-iOS)指定您希望应用程序能够与UIApplication类的canOpenURL:方法一起使用的URL方案。 对于希望您的应用程序与canOpenURL:方法一起使用的每个URL方案,将其作为字符串添加到此数组中。 阅读canOpenURL:方法说明,以获取有关声明支持的方案和使用该方法的重要信息。

有一个示例如何使用它: https : //github.com/gatzsche/LSApplicationQueriesSchemes-Working-Example

尝试这个 :-

if let url = NSURL(string: "zattoo://") {
let canOpen = UIApplication.sharedApplication().canOpenURL(url)

}

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM