3

I'm attempting to write a simple plugin in safari that only needs to check if an application I have developed is installed via javascript. The application launches using a custom uri.

My issue is very similiar to the one presented here, however I'm not developing against iphone\ipad and all I really want is a true\false outcome from my check so that I can present the user with a 'download application or 'launch application' link.

I already have a windows version that works using npruntime for firefox\chrome and ATL for IE which is described here

1 Answer 1

0

Launch Services is the API you need. See the example below:

#include <ApplicationServices/ApplicationServices.h>

bool check_scheme_handler(CFStringRef scheme){
    CFStringRef handler=LSCopyDefaultHandlerForURLScheme(scheme);
    if(handler){
        CFShow(handler);
        CFRelease(handler);
        return true;
    }else{
        CFShow(CFSTR("not found"));
        return false;
    }
}

int main(){
    check_scheme_handler(CFSTR("http"));
    check_scheme_handler(CFSTR("bogus"));
    return 0;
}
3
  • Sorry to be a total noob but could you elaborate a bit more about the process of me implementing and utilizing this method? A point towards a useful tutorial or walkthrough would be greatly appreciated.
    – Amith
    Oct 13, 2010 at 17:47
  • 1
    Well this is the way to detect if a URL scheme is supported or not. This code can be used either inside or outside of Safari plugin. The way to write a Safari/Firefox plugin would be a different question:p
    – Yuji
    Oct 13, 2010 at 20:22
  • It can be used in an NPAPI plugin, but not in a Safari Extension. Right?
    – uchuugaka
    Apr 27, 2015 at 3:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.