确定用户是否已启用应用程序的Safari内容阻止程序扩展 [英] Determine if user has enabled application's Safari content blocker extension
问题描述
我正在开发 Safari内容阻止扩展程序。如果扩展名被禁用,我打算显示设置说明,如果反向启用,则显示设置。如何确定用户是否启用了扩展程序?
I'm working on a Safari Content Blocking extension. I intend to show setup instructions if the extension is disabled and to show settings if it is conversely enabled. How can I determine if the extension is enabled by the user?
我见过此方法检测自定义键盘是否已激活,但<$ c上没有键$ c> NSUserDefaults 与Safari内容拦截器有关。
I've seen this method to detect if a custom keyboard is activated but there's no key on NSUserDefaults
that relates to Safari Content Blockers.
推荐答案
从iOS 10开始,有 SFContentBlockerManager
中的新方法支持这一点:
As of iOS 10, there is a new method in SFContentBlockerManager
to support this:
getStateOfContentBlocker(withIdentifier:completionHandler:)
你打电话给它像这样(Swift 3):
And you call it like this (Swift 3):
SFContentBlockerManager.getStateOfContentBlocker(withIdentifier: "your.identifier.here", completionHandler: { (state, error) in
if let error = error {
// TODO: handle the error
}
if let state = state {
let contentBlockerIsEnabled = state.isEnabled
// TODO: do something with this value
}
})
这篇关于确定用户是否已启用应用程序的Safari内容阻止程序扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!