我有一个Safari App Extension。有没有一种方法可以从包含的应用程序中检测 扩展程序是否已成功安装并在Safari中启用?该文档还有很多不足之处……
答案 0 :(得分:1)
通常,检查方法是通过 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")
}
}
}
}