2

我有一个 Safari 应用程序扩展。如果扩展已在 Safari 中成功安装并启用,有没有办法从包含的应用程序中检测?文档还有很多不足之处……</p>

4

1 回答 1

4

通常检查的方法是通过SFSafariExtensionState-SFSafariExtensionManager如果它被启用,那么它就被安装了。

示例

let extensionIdentifier = "com.acme.MyAppExtension"

@IBOutlet weak var label: NSTextField!
@IBOutlet weak var statusImage: NSImageView!

func checkAppExtension() {
    SFSafariExtensionManager.getStateOfSafariExtension(withIdentifier: extensionIdentifier) { (state, error) in
        DispatchQueue.main.async {
            if (state?.isEnabled ?? false) {
                self.label.stringValue = "MyApp Extension for Safari is enabled"
                self.statusImage.image = NSImage(named: "enabled")
            } else {
                self.label.stringValue = "MyApp Extension for Safari is currently disabled"
                self.statusImage.image = NSImage(named: "disabled")
            }
        }
    }
}
于 2019-01-08T11:05:42.090 回答