gpt4 book ai didi

ios - Zattoo 应用程序 url 方案

转载 作者:行者123 更新时间:2023-11-29 01:20:28 24 4
gpt4 key购买 nike

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

我做的是

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() 总是返回错误(即使我的设备上安装了 Zattoo 应用程序)因此始终执行 else 中的代码。

但是如果删除检查并只执行

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

UIApplication.sharedApplication().openURL(url!)

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

我做错了什么?

最佳答案

在 iOS9 中,您应该注册要用于打开其他应用程序的自定义方案。它应存储为字符串数组(自定义方案),并在 Info.plist 文件中使用 LSApplicationQueriesSchemes 键。来自官方文档(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

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

关于ios - Zattoo 应用程序 url 方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34671055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com