在Windows上使用GitHub Actions和XcodeGen开发iOS应用
两款iOS应用——加密通讯工具Dark Message和暖通工程计算器——已上架App Store。它们完全在Windows上开发,无需MacBook。流程:本地编写代码,通过GitHub Actions中的虚拟macOS机器进行构建和签名。从推送代码到在iPhone上构建完成仅需15分钟。
这绕过了macOS对Xcode的要求。GitHub提供免费的macOS运行器,其中已安装Xcode。设置包括Apple开发者账户、用于从YAML生成项目的XcodeGen、CI/CD流水线以及签名证书。
不同技能水平的开发路径
方法选择取决于技能水平:
- AI辅助编码:Claude Code根据描述生成SwiftUI代码。在Windows终端中运行。示例提示:“SwiftUI iOS应用,使用AES-256-GCM加密和PBKDF2,包含输入/解密界面。”
- 无Mac的程序员:自行编写Swift代码 + AI设置基础设施(XcodeGen、GitHub Actions、证书)。
- 硬核模式:手动配置项目结构、YAML配置、流水线。通过TestFlight迭代,无本地预览。
安装Claude Code:
npm install -g @anthropic-ai/claude-code
claude
AI创建文件,根据反馈进行编辑。无预览,但云端构建弥补了这一不足。
第一步:从俄罗斯注册Apple开发者账户
在appleid.apple.com创建Apple ID(国家≠俄罗斯)。在developer.apple.com/programs/enroll以个人身份注册。年费99美元——使用境外卡(如Bybit)。24–48小时内可访问App Store Connect。
第二步:项目结构和XcodeGen
XcodeGen从project.yml生成.xcodeproj,无需Xcode。示例配置:
name: DarkMessage
options:
bundleIdPrefix: com.darkmessage
deploymentTarget:
iOS: "15.0"
xcodeVersion: "15.0"
targets:
DarkMessage:
type: application
platform: iOS
sources:
- path: Sources
resources:
- path: Resources
settings:
base:
PRODUCT_BUNDLE_IDENTIFIER: com.darkmessage.ios
MARKETING_VERSION: "1.0.0"
CURRENT_PROJECT_VERSION: "1"
SWIFT_VERSION: "5.9"
TARGETED_DEVICE_FAMILY: "1,2"
INFOPLIST_VALUES:
UILaunchScreen: {}
dependencies: []
仓库结构:
Sources/:App.swift、Views/、Models/、Services/(CryptoService.swift)。Resources/Assets.xcassets/。project.yml。.github/workflows/build.yml。
YAML优势:简洁(30行)、无Git冲突、可在VS Code中编辑。
第三步:仓库和GitHub Actions
初始化:
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/user/repo.git
git push -u origin main
macOS运行器构建项目:xcodegen generate、xcodebuild、签名、上传至TestFlight/App Store。
第四步:无Mac代码签名
所需文件:
- 分发证书(.p12)。
- 配置文件(.mobileprovision)。
- App Store Connect API密钥。
在Windows上使用OpenSSL生成CSR:
openssl genrsa -out ios_dist.key 2048
openssl req -new -key ios_dist.key -out ios_dist.csr -subj "/CN=Your Name/[email protected]"
上传CSR至developer.apple.com/account/resources/certificates → Apple Distribution → 下载.cer。转换为.p12:
openssl x509 -inform der -in ios_dist.cer -inkey ios_dist.key -out ios_dist.p12
配置文件:developer.apple.com → Profiles → + → App Store → 包标识符 → 证书。
API密钥:App Store Connect → 用户和访问 → 密钥 → + → App Manager。
在GitHub设置 → Secrets中存储机密:CERTIFICATE_P12_BASE64、PROVISIONING_PROFILE_BASE64、APPSTORE_API_KEY。
第五步:CI/CD工作流YAML
示例.github/workflows/build.yml(简化版):
name: Build iOS
on: [push]
jobs:
build:
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- name: Generate Xcode project
uses: maxim-lobanov/setup-xcodegen@v1
with:
xcodegen-version: '2.35.0'
- run: xcodegen generate
- name: Import certificate
env:
CERTIFICATE_P12: ${{ secrets.CERTIFICATE_P12_BASE64 }}
run: |
echo $CERTIFICATE_P12 | base64 --decode > cert.p12
security import cert.p12 -k ~/Library/Keychains/login.keychain
# ... 签名、归档、上传
完整工作流包括xcodebuild archive、xcrun altool或xcrun notarytool用于App Store。
关键要点
- GitHub Actions的macOS运行器对公共仓库免费(2000分钟/月)。
- XcodeGen简化项目管理,无需Xcode。
- 代码签名通过base64编码的机密自动化。
- 迭代:从推送到TestFlight仅需15分钟。
- 适合一次性项目;生产环境使用Mac可加速开发。
— Editorial Team
暂无评论。