AgentSkillsCN

ios-simulator

与 iOS 模拟器互动,进行移动应用的测试与开发。当您需要测试 iOS 应用、截取屏幕截图、模拟用户交互,或调试移动界面时,可使用此技能。

SKILL.md
--- frontmatter
name: ios-simulator
description: Interact with iOS Simulator for mobile app testing and development. Use when testing iOS apps, taking screenshots, simulating user interactions, or debugging mobile interfaces.

iOS Simulator Testing

When to Use This Skill

  • Testing iOS applications locally
  • Taking screenshots of app states
  • Simulating user interactions
  • Testing different device sizes
  • Debugging mobile UI issues
  • Recording app demonstrations

Prerequisites

bash
# Ensure Xcode is installed
xcode-select --install

# List available simulators
xcrun simctl list devices

# List available runtimes
xcrun simctl list runtimes

Simulator Management

Boot & Shutdown

bash
# Boot a specific simulator
xcrun simctl boot "iPhone 15 Pro"

# Boot by UDID
xcrun simctl boot 12345678-1234-1234-1234-123456789012

# Open Simulator app (shows booted devices)
open -a Simulator

# Shutdown
xcrun simctl shutdown "iPhone 15 Pro"

# Shutdown all
xcrun simctl shutdown all

# Erase (reset to factory)
xcrun simctl erase "iPhone 15 Pro"

Create Custom Simulators

bash
# List device types
xcrun simctl list devicetypes

# Create new simulator
xcrun simctl create "My Test iPhone" "iPhone 15 Pro" "iOS 17.0"

# Delete simulator
xcrun simctl delete "My Test iPhone"

App Installation & Launch

bash
# Install app
xcrun simctl install booted /path/to/MyApp.app

# Uninstall app
xcrun simctl uninstall booted com.company.myapp

# Launch app
xcrun simctl launch booted com.company.myapp

# Launch with arguments
xcrun simctl launch booted com.company.myapp --arg1 value1

# Terminate app
xcrun simctl terminate booted com.company.myapp

Screenshots & Recording

bash
# Take screenshot
xcrun simctl io booted screenshot screenshot.png

# Take screenshot of specific device
xcrun simctl io "iPhone 15 Pro" screenshot ~/Desktop/screenshot.png

# Record video
xcrun simctl io booted recordVideo video.mov

# Stop recording with Ctrl+C
# Or specify duration
timeout 10 xcrun simctl io booted recordVideo demo.mov

User Interaction Simulation

Location

bash
# Set location (latitude, longitude)
xcrun simctl location booted set 37.7749,-122.4194

# Set to Apple Park
xcrun simctl location booted set 37.334606,-122.009102

# Clear location
xcrun simctl location booted clear

Push Notifications

bash
# Create notification payload
cat > notification.json << EOF
{
  "aps": {
    "alert": {
      "title": "Test Notification",
      "body": "This is a test push notification"
    },
    "badge": 1,
    "sound": "default"
  },
  "custom_key": "custom_value"
}
EOF

# Send notification
xcrun simctl push booted com.company.myapp notification.json

URL Schemes

bash
# Open URL
xcrun simctl openurl booted "myapp://deep/link"

# Open web URL
xcrun simctl openurl booted "https://example.com"

Privacy Permissions

bash
# Grant permission
xcrun simctl privacy booted grant photos com.company.myapp
xcrun simctl privacy booted grant camera com.company.myapp
xcrun simctl privacy booted grant microphone com.company.myapp
xcrun simctl privacy booted grant location com.company.myapp

# Revoke permission
xcrun simctl privacy booted revoke photos com.company.myapp

# Reset all permissions
xcrun simctl privacy booted reset all com.company.myapp

Keychain

bash
# Add root certificate
xcrun simctl keychain booted add-root-cert certificate.pem

# Add certificate
xcrun simctl keychain booted add-cert certificate.pem

Data Management

App Data

bash
# Get app container path
xcrun simctl get_app_container booted com.company.myapp data

# Get app bundle path
xcrun simctl get_app_container booted com.company.myapp app

# List installed apps
xcrun simctl listapps booted

Photos & Media

bash
# Add photos to library
xcrun simctl addmedia booted photo1.jpg photo2.png

# Add video
xcrun simctl addmedia booted video.mp4

Clipboard

bash
# Get clipboard contents
xcrun simctl pbpaste booted

# Set clipboard
xcrun simctl pbcopy booted "Text to copy"

Status Bar Customization

bash
# Override status bar (for screenshots)
xcrun simctl status_bar booted override \
  --time "9:41" \
  --batteryState charged \
  --batteryLevel 100 \
  --wifiBars 3 \
  --cellularBars 4

# Clear status bar overrides
xcrun simctl status_bar booted clear

Accessibility

bash
# Enable VoiceOver
xcrun simctl spawn booted defaults write com.apple.Accessibility VoiceOverTouchEnabled -bool true

# Disable VoiceOver
xcrun simctl spawn booted defaults write com.apple.Accessibility VoiceOverTouchEnabled -bool false

Diagnostics

bash
# Get diagnostic report
xcrun simctl diagnose

# Spawn shell command in simulator
xcrun simctl spawn booted log stream --level debug

# View logs
xcrun simctl spawn booted log show --predicate 'subsystem == "com.company.myapp"'

Automation Scripts

Test Multiple Devices

bash
#!/bin/bash
devices=("iPhone 15 Pro" "iPhone 15" "iPhone SE (3rd generation)")

for device in "${devices[@]}"; do
  echo "Testing on $device..."
  xcrun simctl boot "$device"
  xcrun simctl install booted MyApp.app
  xcrun simctl launch booted com.company.myapp
  sleep 5
  xcrun simctl io booted screenshot "screenshot_${device// /_}.png"
  xcrun simctl shutdown "$device"
done

Clean Test Environment

bash
#!/bin/bash
# Reset simulator to clean state
xcrun simctl shutdown all
xcrun simctl erase all
xcrun simctl boot "iPhone 15 Pro"
xcrun simctl install booted MyApp.app
xcrun simctl privacy booted grant all com.company.myapp

Common Device UDIDs

Use xcrun simctl list devices to get current UDIDs, as they vary by installation.

Best Practices

  • Use specific device names/UDIDs in scripts
  • Reset simulator state between test runs
  • Set consistent status bar for screenshots
  • Test on multiple device sizes
  • Clear app data before critical tests
  • Use booted keyword for current device
  • Automate repetitive testing tasks