ios - 如何在 mac OS 应用程序中使用 canOpenURL?

标签 ios objective-c xcode macos

我有一个功能来检查 chrome 是否可以打开一个 url。在 iOS 中我有:

// is chrome installed??
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"googlechrome://"]])
    {
     ...
     }

但现在在我的 Mac OS 应用程序中,我不能使用它,因为它是 NSWorkspace 的未声明函数。

if ([[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"googlechrome://"]])
    {
     ...
     }

那么,如何使用canOpenURL呢?

最佳答案

使用NSWorkspacefullPathForApplication 获取应用程序的包路径。如果该方法返回 nil,则不会安装该应用程序。

相关问题:how to detect if user has an app in Cocoa

关于ios - 如何在 mac OS 应用程序中使用 canOpenURL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40821852/

相关文章:

ios - iPhone5C 中未安装 Luxand SDK

ios - 是否应该限制允许用户查看激励广告的频率?

ios - 看起来像 UIAlertView 的自定义 View

ios - 使用 Storyboard ios5 时从 View Controller 移动到选项卡栏 Controller

objective-c - 将 Swift 导入 Objective-C : Objective-C header "-Swift.h" is not created

ios - 从所有(可见和不可见)UICollectionViewCell 获取框架

html - 在 NSAttributedString 中转换 html 数据的时间太长。有任何想法吗?

html - 使用 C 在 iPad 应用程序中生成动态 HTML?

ios - WatchKit SDK 未从 NSUserDefaults 检索数据

ios - 我希望状态栏在全屏视频播放期间可见