如何在 Safari 中检测应用程序是否已安装

发布于 2024-09-26 23:17:43 字数 549 浏览 0 评论 0原文

我正在尝试在 safari 中编写一个简单的插件,只需要检查我开发的应用程序是否通过 javascript 安装。该应用程序使用自定义 uri 启动。

我的问题与提出的问题非常相似 这里,但是我不是针对 iphone\ipad 进行开发,我真正想要的是我的检查的 true\false 结果,以便我可以向用户呈现“下载应用程序”或“启动应用程序”链接。

我已经有一个 Windows 版本,可以使用适用于 firefox\chrome 的 npruntime 和适用于 IE 的 ATL,其描述为 此处

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哽咽笑 2024-10-03 23:17:43

Launch Services 是您需要的 API。请参阅下面的示例:

#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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文