简体   繁体   中英

Zattoo App url scheme

I need to open Zattoo app from my app (on a button click event)

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.

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. Strange!

What I am doing wrong?

In iOS9 you should register custom schemes you want to use to open other apps. It should be stored as array of strings (custom schemes) with LSApplicationQueriesSchemes key in Info.plist file. From official documentation ( 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. For each URL scheme you want your app to use with the canOpenURL: method, add it as a string in this array. Read the canOpenURL: method description for important information about declaring supported schemes and using that method

There is an example how it can be used: https://github.com/gatzsche/LSApplicationQueriesSchemes-Working-Example

Try this :-

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

}

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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