Safari扩展伴侣始终为空 [英] Safari Extension Companion is always null

查看:84
本文介绍了Safari扩展伴侣始终为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为本地Mac App开发Safari扩展,我想使用

I am developing a Safari Extension for my local Mac App, I want to use SafariExtension Companion to communicate between them.

但是,在扩展名的Global.html中,每当我尝试获取safari.extension.companion时,该值始终为null.我是否将扩展名设置错误?

However, in my Global.html of the extension, whenever I am trying to get safari.extension.companion, it is always null. Do I setup the extension wrong?

此外,根据指南,我可以使用safari.extension.addEventListener侦听来自本地应用程序的消息,但是,当我调试扩展程序时,它提示我safari.extension.addEventListener未定义,为什么?

Besides, according to the guide, I can use safari.extension.addEventListener to listen the message from local app, however, when I debug the extension, it prompts me safari.extension.addEventListener is undefined, why is that?

答案:safari.application.addEventListener是正确的,Apple写错了文档.

我确实在Extension Builder中设置了准确的Companion Bundle Identifier,作为我根据指南在Xcode中为野生动物园同伴设置的标识符.还有其他我想念的吗?请帮忙!!!

I do setup the exact Companion Bundle Identifier in Extension Builder as the identifier which I set in Xcode for the safari companion according to the guide. Is there anything else I miss? Please help!!!

推荐答案

Safari扩展伴侣是一种MacOS X应用扩展名.这些作为应用程序捆绑包的一部分提供.安装应用程序(捆绑包复制到应用程序)后,Safari会选择扩展程序.

A Safari extension companion is a type of a MacOS X app extension. Those are shipped as part of application bundles. When the app is installed (the bundle is copied to Applications), Safari picks up the extension.

首先,您需要一个目标类型为"Cocoa application"(不会使用命令行工具")的Xcode项目.然后,您需要创建一个"Safari Extension Companion"类型的目标,并有机会在创建主应用程序时对其进行指定.

First, you need an Xcode project with a target of type "Cocoa application" ("Command line tool" won't do). Then you need to create a target of type "Safari Extension Companion", and you have a chance to specify the primary app while creating it.

在构建和归档应用程序并导出归档文件时,您可以选择将扩展名添加到应用程序包中.然后安装应用程序捆绑包.

When you build and archive the app, and export the archive, you get an option to add the extension to the app bundle. Then install the app bundle.

确保扩展的捆绑软件ID与Safari Extension Builder中的设置匹配.另外,请确保该应用程序和Safari扩展程序均已签名,并且密钥具有匹配的开发人员ID.对于MacOS X上的证书类型,请选择开发人员ID"-在请求时首先选择,然后在从构建存档中导出捆绑软件时选择

Make sure the bundle ID of the extension matches the setting in the Safari Extension Builder. Also, make sure the app and the Safari extension are both signed, and the keys have matching developer IDs. For certificate type on MacOS X, choose "Developer ID" - first when requesting, then when exporting the bundle from the build archive.

当本地同伴崩溃时,Safari会静默禁用它.如果您删除并重新安装该应用程序捆绑包,然后重新启动Safari,它将再次爱上同伴.

when the native companion crashes, Safari quietly disables it. If you remove and reinstall the app bundle, and also restart Safari, it loves the companion again.

这篇关于Safari扩展伴侣始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆