Notes to Future-Me


Safari Web Extension in SwiftUI

Posted: 2024-10-01
Tags: Xcode

The multiplatform Safari Extension App template is very dated. These are the steps to make a SwiftUI version.

Steps

Create the Main Project

Safari Extensions are delivered inside of a container app.

Stop Targeting VisionOS

Add the Extension Target

(Optional) Consolidate the Files

There may be no need for your extension to have a separate iOS and macOS codebase.

If so, move everything from the “macOS (Extension)” folders into the “Shared (Extension)” folder. The iOS and macOS Info.plist files are identical.

Delete the macOS and iOS Extension folders

Cleanup the Excess Targets

There will now be four new targets in the list. In the TARGETS list:

Fix the Extension Target

In General:

In Build Settings:

Fix the App Target

Switch back to the app’s target in the TARGETS list.

In General, scroll down to Frameworks, Libraries, and Embedded Content:

Signing for macOS

The app will compile at this point for either iOS or macOS, but the extension will not work on macOS.

In order for the extension to be registered on macOS the app and extension must be signed.

In TARGETS (for both the app and extension), open Signing & Capabilities and change the Team to your team signing certificate.