如何在iOS Swift中获取应用程序的CFBundleURLSchemes [英] How to get CFBundleURLSchemes of an app in iOS Swift

查看:837
本文介绍了如何在iOS Swift中获取应用程序的CFBundleURLSchemes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个演示项目App1,其中添加了一个按钮,该按钮会将我重定向到已安装的应用程序,假设App2(" fitbit ")我已经阅读了许多教程,并且基本上了解了如何为此,请通过第二个答案";此应用程序不允许查询方案cydia; IOS9错误.但是在我需要在App1的LSApplicationQueriesSchemes中提到App2的URL Scheme(" fitbit ")时卡住了.

I have made a demo project App1 in which I added a button which will redirect me to the installed app suppose App2("fitbit") I have gone through many tutorials and basically got the idea how to do this through the 2nd answer "This app is not allowed to query for scheme cydia" IOS9 error .but got stucked at a point where I need to mention URL Scheme of App2("fitbit") at LSApplicationQueriesSchemes in App1.

所以基本上,问题是如何获取 fitbit 之类的应用的URL方案.

So basically the question is how to get the URL Schemes of the apps like fitbit.

这是我的代码

var url  = NSURL(string: "itms://itunes.apple.com/in/app/fitbit/id462638897?mt=8")
@IBAction func redirectOnclick(_ sender: Any) {
        let urlFitBt  = NSURL(string: "fitbit://")
        if UIApplication.shared.canOpenURL(urlFitBt! as URL)
        {
            UIApplication.shared.open(urlFitBt! as URL)
        }
        else
        {
            UIApplication.shared.open(url! as URL)

        }

    }

推荐答案

像这样使用

swift 2.2

swift 2.2

        let fitbit = "fitbit://"    //this is fitbit URLSCHEME
        let fitbiturl = NSURL(string: fitbit)

        if UIApplication.sharedApplication().canOpenURL(fitbiturl!)
        {
            UIApplication.sharedApplication().openURL(fitbiturl!)

        } else {
            UIApplication.sharedApplication().openURL(NSURL(string: "https://itunes.apple.com/gb/app/fitbit/id462638897?mt=8&ign-mpt=uo%3D2")!)
        }

并将此行添加到info.plist

and add this line into info.plist

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fitbit</string>
    </array>

这篇关于如何在iOS Swift中获取应用程序的CFBundleURLSchemes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆