macOS 應用程式套件
應用程式套件是在 macOS 上執行的封裝格式。它是一個簡單的目錄,包含您的應用程式成功運作所需的一切,包括您的應用程式執行檔、資源、Info.plist 檔案和其他檔案,例如 macOS 框架。
若要將您的應用程式封裝為 macOS 應用程式套件,您可以使用 Tauri CLI 並在 Mac 電腦上執行 tauri build
指令
npm run tauri build -- --bundles app
yarn tauri build --bundles app
pnpm tauri build --bundles app
deno task tauri build --bundles app
cargo tauri build --bundles app
檔案結構
macOS 應用程式套件是一個具有以下結構的目錄
├── <productName>.app│ ├── Contents│ │ ├── Info.plist│ │ ├── ...additional files from [`tauri.conf.json > bundle > macOS > files`]│ ├── MacOS│ │ ├── <app-name> (app executable)│ ├── Resources│ │ ├── icon.icns (app icon)│ │ ├── ...resources from [`tauri.conf.json > bundle > resources`]│ ├── _CodeSignature (codesign information generated by Apple)│ ├── Frameworks│ ├── PlugIns│ ├── SharedSupport
請參閱官方文件以取得更多資訊。
原生配置
應用程式套件由 Info.plist
檔案配置,其中包含索引鍵值組,其中包含您的應用程式身分和 macOS 讀取的配置值。
Tauri 會自動配置最重要的屬性,例如您的應用程式二進制檔名稱、版本、套件識別符、最低系統版本等等。
若要擴展配置檔,請在 src-tauri
資料夾中建立一個 Info.plist
檔案,並包含您想要的索引鍵值對
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>NSCameraUsageDescription</key> <string>Request camera access for WebRTC</string> <key>NSMicrophoneUsageDescription</key> <string>Request microphone access for WebRTC</string></dict></plist>
此 Info.plist
檔案會與 Tauri CLI 產生值合併。覆寫應用程式版本等預設值時請小心,因為它們可能會與其他配置值衝突並引入非預期的行為。
請參閱官方 Info.plist 文件以取得更多資訊。
Info.plist 本地化
Info.plist
檔案本身僅支援單一語言,通常為英文。如果您想要支援多種語言,您可以為每種額外語言建立 InfoPlist.strings
檔案。每個檔案都屬於應用程式套件中 Resources
目錄中其自己的語言特定 lproj
目錄。
若要自動捆綁這些檔案,您可以利用 Tauri 的資源功能。若要執行此操作,請在您的專案中建立遵循此模式的檔案結構
├── src-tauri│ ├── tauri.conf.json│ ├── infoplist│ │ ├── de.lproj│ │ │ ├── InfoPlist.strings│ │ ├── fr.lproj│ │ │ ├── InfoPlist.strings
雖然 infoplist
目錄名稱可以自由選擇,只要您在下面的資源配置中更新它,lproj
目錄必須遵循 <lang-code>.lproj
命名,並且字串目錄檔案必須命名為 InfoPlist.strings
(大寫 i 和 p)。在大多數情況下,語言代碼應該是遵循 BCP 47 的兩個字母代碼。
對於上面顯示的 Info.plist
範例,de.lproj > InfoPlist.strings
檔案可能如下所示
NSCameraUsageDescription = "Kamera Zugriff wird benötigt für WebRTC Funktionalität";NSMicrophoneUsageDescription = "Mikrofon Zugriff wird benötigt für WebRTC Funktionalität";
最後,讓 Tauri 使用上面提到的資源功能來選取這些檔案
{ "bundle": { "resources": { "infoplist/**": "./" } }}
權限
權限是特殊的 Apple 配置索引鍵值對,作為一種權利或特權,授予您的應用程式特定功能,例如作為使用者的預設電子郵件客戶端和使用 App Sandbox 功能。
權限會在簽署您的應用程式時套用。請參閱程式碼簽署文件以取得更多資訊。
若要定義您的應用程式所需的權限,您必須建立權限檔案並配置 Tauri 以使用它。
- 在
src-tauri
資料夾中建立Entitlements.plist
檔案,並配置您的應用程式所需的索引鍵值對
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>com.apple.security.app-sandbox</key> <true/></dict></plist>
- 配置 Tauri 以使用 Entitlements.plist 檔案
{ "bundle": { "macOS": { "entitlements": "./Entitlements.plist" } }}
請參閱官方文件以取得更多資訊。
最低系統版本
預設情況下,您的 Tauri 應用程式支援 macOS 10.13 及更高版本。如果您使用的 API 需要較新的 macOS 系統,並想要在您的應用程式套件中強制執行該需求,您可以配置 tauri.conf.json > bundle > macOS > minimumSystemVersion
值
{ "bundle": { "macOS": { "minimumSystemVersion": "12.0" } }}
包含 macOS 框架
如果您的應用程式需要額外的 macOS 框架才能執行,您可以在 tauri.conf.json > bundle > macOS > frameworks
配置中列出它們。框架列表可以包含系統框架或自訂框架和 dylib 檔案。
{ "bundle": { "macOS": { "frameworks": [ "CoreAudio", "./libs/libmsodbcsql.18.dylib", "./frameworks/MyApp.framework" ] } }}
新增自訂檔案
您可以使用 tauri.conf.json > bundle > macOS > files
配置將自訂檔案新增至您的應用程式套件,這會將目的地路徑對應到相對於 tauri.conf.json
檔案的來源。這些檔案會新增至 <product-name>.app/Contents
資料夾。
{ "bundle": { "macOS": { "files": { "embedded.provisionprofile": "./profile-name.provisionprofile", "SharedSupport/docs.md": "./docs/index.md" } } }}
在上面的範例中,profile-name.provisionprofile
檔案會複製到 <product-name>.app/Contents/embedded.provisionprofile
,而 docs/index.md
檔案會複製到 <product-name>.app/Contents/SharedSupport/docs.md
。
© 2025 Tauri 貢獻者。CC-BY / MIT