Skip to content
Tauri 中文网

App Store

Apple App Store 是 Apple 维护的应用市场。你可以通过此 App Store 分发针对 macOS 和 iOS 的 Tauri 应用。

¥The Apple App Store is the app marketplace maintained by Apple. You can distribute your Tauri app targeting macOS and iOS via this App Store.

本指南仅介绍将应用直接分发到 App Store 的详细信息。有关 macOS 分发选项和配置的更多信息,请参阅一般 App Bundle

¥This guide only covers details for distributing apps directly to the App Store. See the general App Bundle for more information on macOS distribution options and configurations.

要求

¥Requirements

分发 iOS 和 macOS 应用需要注册 Apple 开发者 程序。

¥Distributing iOS and macOS apps requires enrolling to the Apple Developer program.

此外,你必须为 macOSiOS 设置代码签名。

¥Additionally, you must setup code signing for macOS and iOS.

更改应用图标

¥Changing App Icon

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

¥After running tauri ios init to setup the Xcode project, you can use the tauri icon command to update the app icons.

npm run tauri icon /path/to/app-icon.png -- --ios-color #fff

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

¥The --ios-color argument defines the background color for the iOS icons.

设置

¥Setting up

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

¥After enrolling to the Apple Developer program, the first step to distribute your Tauri app in the App Store is to register your app in the App Store Connect.

:::note 注意

Bundle ID 字段中提供的值必须与 tauri.conf.json > identifier 中定义的标识符匹配。

¥The value provided in the Bundle ID field must match the identifier defined in tauri.conf.json > identifier.

:::

构建和上传

¥Build and upload

Tauri CLI 可以将你的应用打包为 macOS 和 iOS。在 macOS 机器上运行是一项要求。

¥The Tauri CLI can package your app for macOS and iOS. Running on a macOS machine is a requirement.

:::caution 提醒

需要代码签名。请参阅 macOSiOS 的文档。

¥Code signing is required. See the documentation for macOS and iOS.

:::

请注意,Tauri 利用 Xcode 开发 iOS 应用,因此你可以使用 Xcode 而不是 Tauri CLI 来存档和分发 iOS。要在 Xcode 中打开 iOS 项目进行构建,你必须运行以下命令:

¥Note that Tauri leverages Xcode for the iOS app so you can use Xcode to archive and distribute for iOS instead of the Tauri CLI. To open the iOS project in Xcode for building you must run the following command:

npm run tauri ios build -- --open

macOS

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

¥To upload your app to the App Store, first you must ensure all required configuration options are set so you can package the App Bundle, create a signed .pkg file and upload it.

以下部分将指导你完成整个过程。

¥The following sections will guide you through the process.

设置

¥Setup

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

¥Your app must include some configurations to be accepted by the App Store verification system.

:::tip 提示

以下部分将指导你配置应用以进行 App Store 提交。

¥The following sections guides you through configuring your app for App Store submissions.

要仅在为 App Store 构建时应用以下配置更改,你可以创建单独的 Tauri 配置文件:

¥To apply the following config changes only when building for App Store, you can create a separate Tauri configuration file:

"src-tauri/tauri.appstore.conf.json
{
"bundle": {
"macOS": {
"entitlements": "./Entitlements.plist",
"files": {
"embedded.provisionprofile": "path/to/profile-name.provisionprofile"
}
}
}
}

然后在为 App Store 打包 Tauri 应用时将该配置文件与主文件合并:

¥Then merge that config file with the main one when bundling your Tauri app for App Store:

npm run tauri build -- --no-bundle
npm run tauri bundle -- --bundles app --target universal-apple-darwin --config src-tauri/tauri.appstore.conf.json

这在设置 CI/CD 以将你的应用上传到 App Store 时特别​​有用,同时不需要本地配置文件,或者在编译应用以在 App Store 之外分发时。

¥This is particularly useful when setting up your CI/CD to upload your app to the App Store while not requiring the provision profile locally or when compiling the app for distribution outside the App Store.

:::

  • 类别

    ¥Category

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

¥Your app must define its tauri.conf.json > bundle > category to be displayed in the App Store:

tauri.conf.json
{
"bundle": {
"category": "Utility"
}
}
  • 配置文件

    ¥Provisioning profile

你还必须为你的应用创建一个配置文件,以便 Apple 接受。

¥You must also create a provisioning profile for your app to be accepted by Apple.

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

¥In the Identifiers page, create a new App ID and make sure its “Bundle ID” value matches the identifier set in tauri.conf.json > identifier.

导航到 配置文件 页面以创建新的配置文件。对于 App Store macOS 分发,它必须是 “Mac App Store Connect” 配置文件。选择适当的 App ID 并链接你用于代码签名的证书。

¥Navigate to the Profiles page to create a new provisioning profile. For App Store macOS distribution, it must be a “Mac App Store Connect” profile. Select the appropriate App ID and link the certificate you are using for code signing.

创建配置文件后,下载它并将其保存到已知位置并配置 Tauri 以将其包含在你的应用包中:

¥After creating the provisioning profile, download it and save it to a known location and configure Tauri to include it in your app bundle:

tauri.conf.json
{
"bundle": {
"macOS": {
"files": {
"embedded.provisionprofile": "path/to/profile-name.provisionprofile"
}
}
}
}
  • Info.plist

你的应用必须符合加密导出规定。有关更多信息,请参阅 官方文档

¥Your app must comply with encryption export regulations. See the official documentation for more information.

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

¥Create a Info.plist file in the src-tauri folder:

<?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/> # or `true` if your app uses encryption
</dict>
</plist>
  • 权利

    ¥Entitlements

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

¥Your app must include the App Sandbox capability to be distributed in the App Store. Additionally, you must also set your App ID and Team ID in the code signing entitlements.

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

¥Create a Entitlements.plist file in the src-tauri folder:

<?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 开发者团队 ID,该 ID 可以在你为配置文件创建的 标识符 中的 App ID Prefix 部分中找到。

¥Note that you must replace $IDENTIFIER with the tauri.conf.json > identifier value and $TEAM_ID with your Apple Developer team ID, which can be found in the App ID Prefix section in the Identifier you created for the provisioning profile.

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

¥And reference that file in the macOS bundle configuration tauri.conf.json > bundle > macOS > entitlements:

tauri.conf.json
{
"bundle": {
"macOS": {
"entitlements": "./Entitlements.plist"
}
}
}

现在,你必须在启用代码签名的情况下构建应用才能应用权利。

¥You now must build your application with code signing enabled for the entitlements to apply.

确保你的应用在应用沙盒上下文中运行时可以正常工作。

¥Make sure your app works when running in an App Sandbox context.

构建

¥Build

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

¥You must upload your macOS application as a .pkg file to the App Store. Run the following command to package your app as a macOS App Bundle (.app extension):

tauri build --bundles app --target universal-apple-darwin

:::note 注意

上面的命令创建一个 Universal App Binary 应用,支持 Apple Silicon 和 Intel 处理器。

¥The above command creates an Universal App Binary application, supporting both Apple Silicon and Intel processors.

如果你更喜欢仅支持 Apple Silicon,则必须将 tauri.conf.json > bundle > macOS > minimumSystemVersion 更改为 12.0

¥If you prefer to only support Apple Silicon instead, you must change tauri.conf.json > bundle > macOS > minimumSystemVersion to 12.0:

tauri.conf.json
{
"bundle": {
"macOS": {
"minimumSystemVersion": "12.0"
}
}
}

并根据你正在运行的 Mac 系统更改 CLI 命令和输出路径:

¥And change the CLI command and output path based on the Mac system you are running:

  • 如果你的构建系统使用 Apple Silicon 芯片,请删除 --target universal-apple-darwin 参数并在下面引用的路径中使用 target/release 而不是 target/universal-apple-darwin/release

    ¥if your build system uses an Apple Silicon chip, remove the --target universal-apple-darwin arguments and use target/release instead of target/universal-apple-darwin/release in the paths referenced below.

  • 如果你的构建系统使用 Intel 芯片:

    ¥if your build system uses an Intel chip:

    • 安装 Rust Apple Silicon 目标:

      ¥install the Rust Apple Silicon target:

      rustup target add aarch64-apple-darwin
    • universal-apple-darwin 参数更改为 aarch64-apple-darwin,并在下面引用的路径中使用 target/aarch64-apple-darwin/release 而不是 target/universal-apple-darwin/release

      ¥change the universal-apple-darwin argument to aarch64-apple-darwin and use target/aarch64-apple-darwin/release instead of target/universal-apple-darwin/release in the paths referenced below.

:::

有关其他选项的更多信息,请参阅 App Bundle 分发指南

¥See the App Bundle distribution guide for more information on configuration options.

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

¥To generate a signed .pkg from your app bundle, run the following command:

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

请注意,你必须将 $APPNAME 替换为你的应用名称。

¥Note that you must replace $APPNAME with your app name.

:::note 注意

你必须使用 Mac 安装程序分发签名证书对 PKG 进行签名。

¥You must sign the PKG with a Mac Installer Distribution signing certificate.

:::

上传

¥Upload

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

¥Now you can use the altool CLI to upload your app PKG to the 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 密钥才能上传你的应用。有关更多信息,请参阅 身份验证部分

¥Note that altool requires an App Store Connect API key to upload your app. See the authentication section for more information.

然后,你的应用将由 Apple 验证,如果获得批准,则可在 TestFlight 中获取。

¥Your app will then be validated by Apple and available in TestFlight if approved.

iOS

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

¥To build your iOS app, run the tauri ios build command:

npm run tauri ios build -- --export-method app-store-connect

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

¥The generated IPA file can be found in src-tauri/gen/apple/build/arm64/$APPNAME.ipa.

请注意,你必须将 $APPNAME 替换为你的应用名称。

¥Note that you must replace $APPNAME with your app name.

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

¥Now you can use the altool CLI to upload your iOS app to the 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 密钥才能上传你的应用。有关更多信息,请参阅 身份验证部分

¥Note that altool requires an App Store Connect API key to upload your app. See the authentication section for more information.

然后,你的应用将由 Apple 验证,如果获得批准,则可在 TestFlight 中获取。

¥Your app will then be validated by Apple and available in TestFlight if approved.

身份验证

¥Authentication

iOS 和 macOS 应用使用 altool 上传,它使用 App Store Connect API 密钥进行身份验证。

¥The iOS and macOS apps are uploaded using altool, which uses an App Store Connect API key to authenticate.

要创建新的 API 密钥,请打开 App Store Connect 的用户和访问页面,选择 Integrations > Individual Keys 选项卡,单击 Add 按钮并选择名称和 Developer 访问权限。APPLE_API_ISSUER(发行者 ID)显示在密钥表上方,APPLE_API_KEY_ID 是该表上密钥 ID 列的值。你还需要下载私钥,该操作只能执行一次,并且仅在页面重新加载后可见(按​​钮显示在新创建密钥的表格行上)。私钥文件路径必须作为 AuthKey\_<APPLE_API_KEY_ID>.p8 保存在以下目录之一中:<current-working-directory>/private_keys~/private_keys~/.private_keys~/.appstoreconnect/private_keys

¥To create a new API key, open the App Store Connect’s Users and Access page, select the Integrations > Individual Keys tab, click on the Add button and select a name and the Developer access. The APPLE_API_ISSUER (Issuer ID) is presented above the keys table, and the APPLE_API_KEY_ID is the value on the Key ID column on that table. You also need to download the private key, which can only be done once and is only visible after a page reload (the button is shown on the table row for the newly created key). The private key file path must be saved as AuthKey\_<APPLE_API_KEY_ID>.p8 in one of these directories:<current-working-directory>/private_keys, ~/private_keys, ~/.private_keysor~/.appstoreconnect/private_keys.


Tauri 中文网 - 粤ICP备13048890号