以编程方式检查是否安装了应用程序 [英] Programmatically check whether an app is installed

查看:60
本文介绍了以编程方式检查是否安装了应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有以下 Objective-C 代码的 Swift 等价物

I would like to know whether there is a Swift equivalent of the following Objective-C code

NSURL *appURL = [NSURL URLWithString: @"myapp://"];
if ([app canOpenURL: appURL] {
 NSLog(@"The app is this URL Scheme is installed on the device");
}

推荐答案

在阅读此答案之前,您必须郑重宣誓不会在您链接到的页面上进行任何活动.(寻找约会应用程序?认真的?)

Before reading this answer you must solemnly swear not to do any of the activities on the page you linked to. (Looking for dating apps? Seriously?)

方法基本相同:

if let appURL = NSURL(string: "myapp://test/url/") {
    let canOpen = UIApplication.sharedApplication().canOpenURL(appURL)
    println("Can open \"\(appURL)\": \(canOpen)")
}

这篇关于以编程方式检查是否安装了应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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