Determine if user has enabled application's Safari content blocker extension

前端 未结 2 1298
抹茶落季
抹茶落季 2020-12-15 20:46

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 c

2条回答
  •  旧巷少年郎
    2020-12-15 21:20

    As of iOS 10, there is a new method in SFContentBlockerManager to support this:

    getStateOfContentBlocker(withIdentifier:completionHandler:)

    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
        }
    })
    

提交回复
热议问题