3 App Store

原文链接: https://tauri.app/distribute/app-store/

Apple App Store 是 Apple 维护的应用市场。 你可以通过该 App Store 分发面向 macOS 和 iOS 的 Tauri 应用。

本指南只涵盖把应用直接分发到 App Store 的细节。 关于 macOS 分发选项与配置的更多信息,请参阅通用的 App Bundle 分发指南。

要求

分发 iOS 和 macOS 应用需要注册 Apple Developer 计划。

此外,你还必须为 macOS 和 iOS 设置代码签名。

更换应用图标

运行 tauri ios init 设置好 Xcode 项目之后,你可以使用 tauri icon 命令更新应用图标。

包管理器

1
npm run tauri icon /path/to/app-icon.png -- --ios-color '#fff'
1
yarn tauri icon /path/to/app-icon.png --ios-color '#fff'
1
pnpm tauri icon /path/to/app-icon.png --ios-color '#fff'
1
deno task tauri icon /path/to/app-icon.png --ios-color '#fff'
1
bun tauri icon /path/to/app-icon.png --ios-color '#fff'
1
cargo tauri icon /path/to/app-icon.png --ios-color '#fff'

--ios-color 参数定义 iOS 图标的背景色。

配置

注册 Apple Developer 计划之后,在 App Store 中分发 Tauri 应用的第一步 是在 App Store Connect 中注册你的应用。

构建与上传

Tauri CLI 可以为 macOS 和 iOS 打包你的应用。必须在 macOS 机器上运行。

Tauri 会从 tauri.conf.json > version 中定义的值推导 CFBundleVersion。 如果你需要不同的 bundle 版本方案(例如顺序编号),可以在 tauri.conf.json > bundle > iOS > bundleVersion 或 tauri.conf.json > bundle > macOS > bundleVersion 配置中设置自定义 bundle 版本:

1
2
3
4
5
6
7
{
  "bundle": {
    "iOS": {
      "bundleVersion": "100"
    }
  }
}

注意 Tauri 为 iOS 应用借助了 Xcode,因此你也可以用 Xcode 归档并分发 iOS 应用,而不使用 Tauri CLI。 要在 Xcode 中打开 iOS 项目以进行构建,你必须运行以下命令:

包管理器

1
npm run tauri ios build -- --open
1
yarn tauri ios build --open
1
pnpm tauri ios build --open
1
deno task tauri ios build --open
1
bun tauri ios build --open
1
cargo tauri ios build --open

macOS

要把应用上传到 App Store,你首先必须确保所有必需的配置项都已设置, 以便你可以打包 App Bundle、创建已签名的 .pkg 文件并上传它。

下面几节将带你完成该过程。

设置

你的应用必须包含一些配置,才能被 App Store 的验证系统接受。

包管理器

1
2
npm run tauri build -- --no-bundle
npm run tauri bundle -- --bundles app --target universal-apple-darwin --config src-tauri/tauri.appstore.conf.json
1
2
yarn tauri build --no-bundle
yarn tauri bundle --bundles app --target universal-apple-darwin --config src-tauri/tauri.appstore.conf.json
1
2
pnpm tauri build --no-bundle
pnpm tauri bundle --bundles app --target universal-apple-darwin --config src-tauri/tauri.appstore.conf.json
1
2
deno task tauri build --no-bundle
deno task tauri bundle --bundles app --target universal-apple-darwin --config src-tauri/tauri.appstore.conf.json
1
2
bun tauri build --no-bundle
bun tauri bundle --bundles app --target universal-apple-darwin --config src-tauri/tauri.appstore.conf.json
1
2
cargo tauri build --no-bundle
cargo tauri bundle --bundles app --target universal-apple-darwin --config src-tauri/tauri.appstore.conf.json

当你在 CI/CD 中把应用上传到 App Store,而本地不需要描述文件,或者还要为 App Store 之外的分发编译应用时,这尤其有用。

  • 分类

你的应用必须定义 tauri.conf.json > bundle > category 才能显示在 App Store 中:

1
2
3
4
5
{
  "bundle": {
    "category": "Utility"
  }
}
  • 描述文件

你还必须为应用创建描述文件,才能被 Apple 接受。

在 Identifiers 页面中, 创建一个新的 App ID,并确保它的 “Bundle ID” 值与 tauri.conf.json > identifier 中设置的标识符一致。

前往 Profiles 页面创建一个新的描述文件。 对于 macOS 的 App Store 分发,它必须是 “Mac App Store Connect” 描述文件。 选择恰当的 App ID,并关联你用于代码签名的证书。

创建描述文件之后,下载它并保存到已知位置,然后配置 Tauri 将其包含进应用程序包:

1
2
3
4
5
6
7
8
9
{
  "bundle": {
    "macOS": {
      "files": {
        "embedded.provisionprofile": "path/to/profile-name.provisionprofile"
      }
    }
  }
}
  • Info.plist

你的应用必须遵守加密出口法规。 更多信息请参阅官方文档。

在 src-tauri 文件夹中创建 Info.plist 文件:

1
2
3
4
5
6
7
8
<?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>ITSAppUsesNonExemptEncryption</key>
	<false/> # 如果你的应用使用加密,请改为 `true`
</dict>
</plist>
  • 授权

你的应用必须包含 App Sandbox 能力才能在 App Store 中分发。 此外,你还必须在代码签名授权中设置 App ID 和 Team ID。

在 src-tauri 文件夹中创建 Entitlements.plist 文件:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?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/>
    <key>com.apple.application-identifier</key>
    <string>$TEAM_ID.$IDENTIFIER</string>
    <key>com.apple.developer.team-identifier</key>
    <string>$TEAM_ID</string>
</dict>
</plist>

注意你必须把 $IDENTIFIER 替换为 tauri.conf.json > identifier 的值, 把 $TEAM_ID 替换为你的 Apple Developer team ID,它可以在你为描述文件创建的 Identifier 的 App ID Prefix 部分找到。

并在 macOS 打包配置 tauri.conf.json > bundle > macOS > entitlements 中引用该文件:

1
2
3
4
5
6
7
{
  "bundle": {
    "macOS": {
      "entitlements": "./Entitlements.plist"
    }
  }
}

现在你必须在启用代码签名的情况下构建应用,授权才会生效。

请确保你的应用在 App Sandbox 环境中能正常工作。

构建

你必须把 macOS 应用以 .pkg 文件上传到 App Store。 运行以下命令把你的应用打包为 macOS App Bundle(.app 扩展名):

包管理器

1
npm run tauri build -- --bundles app --target universal-apple-darwin
1
yarn tauri build --bundles app --target universal-apple-darwin
1
pnpm tauri build --bundles app --target universal-apple-darwin
1
deno task tauri build --bundles app --target universal-apple-darwin
1
bun tauri build --bundles app --target universal-apple-darwin
1
cargo tauri build --bundles app --target universal-apple-darwin

关于配置选项的更多信息,请参阅 App Bundle 分发指南。

要从应用包生成已签名的 .pkg,请运行以下命令:

xcrun productbuild --sign "<certificate signing identity>" --component "target/universal-apple-darwin/release/bundle/macos/$APPNAME.app" /Applications "$APPNAME.pkg"

注意你必须把 $APPNAME 替换为你的应用名。

上传

现在你可以使用 altool CLI 把应用的 PKG 上传到 App Store:

xcrun altool --upload-app --type macos --file "$APPNAME.pkg" --apiKey $APPLE_API_KEY_ID --apiIssuer $APPLE_API_ISSUER

注意 altool 需要 App Store Connect API 密钥才能上传应用。 更多信息请参阅认证一节。

随后你的应用会由 Apple 验证,若通过则在 TestFlight 中可用。

iOS

要构建 iOS 应用,请运行 tauri ios build 命令:

包管理器

1
npm run tauri ios build -- --export-method app-store-connect
1
yarn tauri ios build --export-method app-store-connect
1
pnpm tauri ios build --export-method app-store-connect
1
deno task tauri ios build --export-method app-store-connect
1
bun tauri ios build --export-method app-store-connect
1
cargo tauri ios build --export-method app-store-connect

生成的 IPA 文件可以在 src-tauri/gen/apple/build/arm64/$APPNAME.ipa 找到。

注意你必须把 $APPNAME 替换为你的应用名。

现在你可以使用 altool CLI 把 iOS 应用上传到 App Store:

xcrun altool --upload-app --type ios --file "src-tauri/gen/apple/build/arm64/$APPNAME.ipa" --apiKey $APPLE_API_KEY_ID --apiIssuer $APPLE_API_ISSUER

注意 altool 需要 App Store Connect API 密钥才能上传应用。 更多信息请参阅认证一节。

随后你的应用会由 Apple 验证,若通过则在 TestFlight 中可用。

认证

iOS 和 macOS 应用通过 altool 上传,它使用 App Store Connect API 密钥进行认证。

要创建新的 API 密钥,请打开 App Store Connect 的 Users and Access 页面,选择 Integrations > Individual Keys 标签,点击 Add 按钮,选择名称与 Developer 权限。 APPLE_API_ISSUER(Issuer ID)显示在密钥表格上方,APPLE_API_KEY_ID 是该表格 Key ID 列中的值。 你还需要下载私钥,这只能做一次,并且只在页面重新加载后可见(按钮显示在新建密钥所在表格行上)。 私钥文件路径必须保存为 AuthKey\_<APPLE_API_KEY_ID>.p8,并放在以下目录之一:<current-working-directory>/private_keys、~/private_keys、~/.private_keys 或 ~/.appstoreconnect/private_keys。

最后修改 September 26, 2026: 更新 (630b11f59)