This document provides detailed instructions for building the TwoFactorAuth application on macOS.
- macOS 12.0 or later
- Xcode 14.0 or later (for Xcode build method)
- Swift 5.7 or later (for command line build)
- Developer ID certificate (optional, for signed builds)
-
Open the project in Xcode:
open Package.swift
Or double-click
Package.swiftin Finder -
Select the build scheme:
- In Xcode, select "TwoFactorAuth" from the scheme selector in the toolbar
- Choose "My Mac" as the destination
-
Build the application:
- Press
⌘Bto build, or - Select Product → Build from the menu
- Press
-
Run the application:
- Press
⌘Rto run, or - Select Product → Run from the menu
- Press
-
Archive for distribution (optional):
- Select Product → Archive
- Once archived, click "Distribute App"
- Choose "Copy App" for local distribution
-
Build for debug:
swift build
-
Build for release:
swift build -c release
-
Run the application:
swift run TwoFactorAuth
-
Build the release executable:
# Build for release swift build -c release --arch arm64 --arch x86_64 -
Locate the built executable:
# The executable will be at: ls .build/release/TwoFactorAuth -
Create an app bundle:
# Create the app bundle structure mkdir -p TwoFactorAuth.app/Contents/{MacOS,Resources} # Copy the executable cp .build/release/TwoFactorAuth TwoFactorAuth.app/Contents/MacOS/ # Copy Info.plist (create one if it doesn't exist) cat > TwoFactorAuth.app/Contents/Info.plist << EOF <?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>CFBundleExecutable</key> <string>TwoFactorAuth</string> <key>CFBundleIdentifier</key> <string>com.yourcompany.TwoFactorAuth</string> <key>CFBundleName</key> <string>TwoFactorAuth</string> <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleShortVersionString</key> <string>1.0.0</string> <key>CFBundleVersion</key> <string>1</string> <key>LSMinimumSystemVersion</key> <string>12.0</string> </dict> </plist> EOF # Copy assets if available if [ -d "TwoFactorAuth/Assets.xcassets" ]; then cp -r TwoFactorAuth/Assets.xcassets TwoFactorAuth.app/Contents/Resources/ fi
-
Install to Applications folder:
# Copy to Applications sudo cp -r TwoFactorAuth.app /Applications/
-
Build the app using any method above
-
Create a distribution folder:
# Create a temporary distribution folder mkdir -p dist/TwoFactorAuth # Copy the app bundle cp -r TwoFactorAuth.app dist/TwoFactorAuth/ # Create a symbolic link to Applications ln -s /Applications dist/TwoFactorAuth/Applications
-
Create the DMG:
# Create DMG with compression hdiutil create -volname "TwoFactorAuth" \ -srcfolder dist/TwoFactorAuth \ -ov \ -format UDZO \ TwoFactorAuth.dmg
-
Clean up:
rm -rf dist
Create a build.sh script for one-command builds:
#!/bin/bash
# build.sh - Automated build script for TwoFactorAuth
set -e # Exit on error
echo "🔨 Building TwoFactorAuth..."
# Clean previous builds
rm -rf .build TwoFactorAuth.app TwoFactorAuth.dmg
# Build release version (universal binary)
echo "📦 Building release executable..."
swift build -c release --arch arm64 --arch x86_64
# Create app bundle
echo "📁 Creating app bundle..."
mkdir -p TwoFactorAuth.app/Contents/{MacOS,Resources}
cp .build/release/TwoFactorAuth TwoFactorAuth.app/Contents/MacOS/
# Create Info.plist
cat > TwoFactorAuth.app/Contents/Info.plist << EOF
<?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>CFBundleExecutable</key>
<string>TwoFactorAuth</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.TwoFactorAuth</string>
<key>CFBundleName</key>
<string>TwoFactorAuth</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>12.0</string>
</dict>
</plist>
EOF
# Copy assets if they exist
if [ -d "TwoFactorAuth/Assets.xcassets" ]; then
cp -r TwoFactorAuth/Assets.xcassets TwoFactorAuth.app/Contents/Resources/
fi
# Create DMG
echo "💿 Creating DMG..."
mkdir -p dist/TwoFactorAuth
cp -r TwoFactorAuth.app dist/TwoFactorAuth/
ln -s /Applications dist/TwoFactorAuth/Applications
hdiutil create -volname "TwoFactorAuth" \
-srcfolder dist/TwoFactorAuth \
-ov \
-format UDZO \
TwoFactorAuth.dmg
# Clean up
rm -rf dist
echo "✅ Build complete!"
echo "📍 App bundle: TwoFactorAuth.app"
echo "📍 DMG file: TwoFactorAuth.dmg"Make the script executable:
chmod +x build.shRun the build:
./build.shTo sign your application for distribution outside the Mac App Store:
-
List available certificates:
security find-identity -v -p codesigning
-
Sign the app:
codesign --force --deep --sign "Developer ID Application: Your Name" TwoFactorAuth.app -
Verify the signature:
codesign --verify --verbose TwoFactorAuth.app
-
Notarize for Gatekeeper (requires Apple Developer account):
# Create a zip for notarization ditto -c -k --keepParent TwoFactorAuth.app TwoFactorAuth.zip # Submit for notarization xcrun notarytool submit TwoFactorAuth.zip \ --apple-id "your-apple-id@example.com" \ --team-id "YOUR_TEAM_ID" \ --password "your-app-specific-password" \ --wait # Staple the notarization xcrun stapler staple TwoFactorAuth.app
- Module not found: Run
swift package resolveto fetch dependencies - Architecture issues: Ensure you're building for the correct architecture
- Permission denied: Use
sudofor copying to/Applications
- App won't open: Check System Preferences → Security & Privacy
- Missing dependencies: Verify all Swift packages are included
- Crash on launch: Check Console.app for crash logs