检查是否使用Swift安装了应用程序

Rom*_*ain 4 swift

我想知道是否存在Swift等效的以下Objective-C代码(如http://urlschemes.com/中所述):

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

Nat*_*ook 10

在阅读本回答之前,您必须郑重宣誓不要在您链接的页面上进行任何活动.(寻找约会应用程序?严重吗?)

方法基本相同:

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


Alv*_*ani 5

让我们采用两个名为 A 和 B 的应用程序。

现在我想从应用程序 A 打开应用程序 B,因此首先在应用程序 B 中创建 URLSchema。

将以下代码添加到应用程序 A 中的 info.plist 文件中。

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>app b schema Name</string>
</array>
Run Code Online (Sandbox Code Playgroud)

现在将以下代码添加到要从其中打开应用程序 B 的应用程序 A。

UIApplication.shared.canOpenURL(URL(string:"app b schema Name://")! as URL)
Run Code Online (Sandbox Code Playgroud)

谢谢。