0

I'm developing a Safari App Extension inside a macOS app. When a user installs this app, the extension is added to Safari, but it's disabled by default. We can detect the state of extension by using SFSafariExtensionManager class via its getStateOfSafariExtension method.

Now I want to enable the extension state programmatically if it is disabled. How can I achieve that? Or do anyone have any idea where the preferences / app extensions settings are stored in macOS?

sam
  • 481
  • 2
  • 8
  • 21

1 Answers1

1

You can create a button such as "Open extension preferences" to show Safari preferences directly for your extension then the user could enable it.

The code for your app:

import SafariServices

func enableExtension () {
    SFSafariApplication.showPreferencesForExtension(withIdentifier: YOUR_EXTENSION_IDENTIFIER) { (error) in
        NSLog("Error \(String(describing: error))")
    }
}

SFSafariApplication could be used in Cocoa app only (not extension).

seclace
  • 98
  • 7
  • I already know that how to open extension preferences window by using SFSafariApplication class. I want to enable the extension without user interaction. – sam Mar 07 '19 at 13:27
  • It is impossible due to security reasons. What if the extension could manage other extensions without user intent? Right, it is bad to give such abilities to extension. – seclace Mar 07 '19 at 22:21
  • @ВадимГолденко is there anyway to disable it through code or just like enabling, it is also restricted by apple? – Nauman Aslam Aug 15 '19 at 14:41