检测是否安装并启用了 Safari App Extension
Detecting if Safari App Extension is installed and enabled
我有一个 Safari 应用程序扩展。如果扩展已成功安装并在 Safari 中启用,是否有方法从包含的应用程序检测?文档还有很多不足之处……
一般检查方法是通过SFSafariExtensionState
and 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")
}
}
}
}
我有一个 Safari 应用程序扩展。如果扩展已成功安装并在 Safari 中启用,是否有方法从包含的应用程序检测?文档还有很多不足之处……
一般检查方法是通过SFSafariExtensionState
and 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")
}
}
}
}