How to create a Safari Extension Companion in Xcode 8.2.1? template is missing

I want to create a Safari Extension Companion , but the option to create a Safari extension does not appear.

What is the correct way to create an extension?

enter image description here

+5
source share
2 answers

To create a Safari application extension, you add a new target to an existing project in Xcode. - mentioned in the documentation.

  • Launch Xcode and open an existing project containing an OS X application, or create a new one.

  • Create a new goal by choosing File> New> Target.

  • In the New Target sheet, look in the left sidebar and select the OS X application extension.

  • In the list of templates on the right, select "Safari Extension" and click "Next."

enter image description here

  1. Enter a product name for your extension, for example, "My Extension."

  2. Make sure your application project is selected in the Project menu, and the application target of the OS X application is selected in Embed in the application menu.

  3. Click Finish.

  4. When Xcode asks you if you want to activate a new scheme for your new extension, click the "Cancel" button.


Xcode adds a new group to your project that contains several new files, including the Info.plist file, many supporting source files, an interface builder file, a JavaScript file, and a PDF file in the toolbar.

* There may be a few more steps, although I'm sure you can handle it ...

↳ Add Safari app extension target in Xcode

+6
source

The easiest way is to simply install Xcode 7 side by side with Xcode 8 - this works fine - and upload your project to 7. Create a target companion companion, but do nothing with it. Close Xcode 7 and open Xcode 8 in the same project / workspace and you will see a companion. If you use Swift, you will need to upgrade the language (Xcode 7 uses Swift 2, Xcode 8 uses Swift 3); The IDE will suggest some changes directly when trying to compile, but others that you may need to change manually.

Alternatively / more inconveniently, you can create a new target (e.g., Safari extension) in Xcode 8, and then delete extraneous files (e.g. JavaScript to insert content) and edit / replace the plist in the extension with the plist of the additional companion. Key property <string>com.apple.Safari.extension-companion</string> for NSExtensionPointIdentifier ; also make sure that NSExtensionPrincipalClass implements the protocol for companion extensions (both of these keys are under NSExtension ).

Remember that I had mixed results with this approach. Sometimes it works, sometimes Safari pretends that it does not see the extension companion at all, sometimes the extension cannot see the companion until you restart it, and then it can ... If you can see the extension companion, it should (note the warning here about if the concomitant accident crashes), and I did not find any protocols that help fix these problems. Trying to debug an extra companion using Xcode 8 doesn't work for me either.

I am sorry that Apple did not insist so much on β€œthinking” and simply supported Native Messaging like every other modern browser.

+2
source

Source: https://habr.com/ru/post/1264129/


All Articles