简体   繁体   English

Zattoo App网址方案

[英]Zattoo App url scheme

I need to open Zattoo app from my app (on a button click event) 我需要从我的应用程序中打开Zattoo应用程序(在按钮单击事件上)

what I have done is 我所做的是

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() always returns me the false (even Zattoo app is installed on my device) hence the code in else is executed always. canOpenURL()总是返回false(即使我的设备上安装了Zattoo应用程序),因此else中的代码也总是执行。

but if removing the check and just executing the 但是,如果删除检查并仅执行

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

 UIApplication.sharedApplication().openURL(url!)

It's opening the the Zattoo app perfectly. 它完美地打开了Zattoo应用程序。 Strange! 奇怪!

What I am doing wrong? 我做错了什么?

In iOS9 you should register custom schemes you want to use to open other apps. 在iOS9中,您应该注册要用于打开其他应用程序的自定义方案。 It should be stored as array of strings (custom schemes) with LSApplicationQueriesSchemes key in Info.plist file. 它应该被存储为字符串(定制方案)与阵列LSApplicationQueriesSchemes在关键Info.plist文件。 From official documentation ( https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW14 ) : 从官方文档( https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW14 ):

LSApplicationQueriesSchemes (Array - iOS) Specifies the URL schemes you want the app to be able to use with the canOpenURL: method of the UIApplication class. LSApplicationQueriesSchemes(Array-iOS)指定您希望应用程序能够与UIApplication类的canOpenURL:方法一起使用的URL方案。 For each URL scheme you want your app to use with the canOpenURL: method, add it as a string in this array. 对于希望您的应用程序与canOpenURL:方法一起使用的每个URL方案,将其作为字符串添加到此数组中。 Read the canOpenURL: method description for important information about declaring supported schemes and using that method 阅读canOpenURL:方法说明,以获取有关声明支持的方案和使用该方法的重要信息。

There is an example how it can be used: https://github.com/gatzsche/LSApplicationQueriesSchemes-Working-Example 有一个示例如何使用它: https : //github.com/gatzsche/LSApplicationQueriesSchemes-Working-Example

Try this :- 尝试这个 :-

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

} }

Hope it helps. 希望能帮助到你。

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

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