user3745888 user3745888 - 1 year ago 118
Objective-C Question

How to use canOpenURL in mac OS application?

I had a function to check if chrome could be open an url. In iOS I had:

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

But now in my app to Mac OS, I can't use this, because is undeclared function with NSWorkspace.

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

So, how can use canOpenURL?

Cee Cee
Answer Source

Use NSWorkspace's fullPathForApplication to get an application's bundle path. If that method returns nil, the app is not installed.

Related question: how to detect if user has an app in Cocoa

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download