agentleFS
Jeff-TianJeff-Tian/agent-skills/app-store-version-check/SKILL.md

app-store-version-check

Skill1 starsChanged 7 months agoMITView on GitHub

Add or fix in-app update checking for Apple platform apps, especially SwiftUI About pages that should show whether a newer App Store version exists and let users open the App Store or Mac App Store update page. Use when the user asks for "check latest version", "About page update button", "App Store version lookup", "Mac App Store update", "iTunes Lookup API", or when an attempted custom version endpoint returns 404.

The file

Show its rules and text

We split this skill into the rules it gives an agent

25 rules. About 0 are common, 20 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈20

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when adding update visibility to an iOS, iPadOS, or macOS app.

    line 14
  2. Very specific:

    Instead, scrape the App Store product page HTML.

    line 27
  3. Distinctive:

    Only use iTunes Lookup when:

    line 41
  4. Distinctive:

    Use a custom static JSON endpoint only when the app needs non-App-Store channels such as TestFlight, enterprise distribution, staged …

    line 48
  5. Distinctive:

    When implementing in a codebase that expects TDD, follow red-green-refactor:

    line 54
  6. Distinctive:

    Write pure logic tests first.

    line 56
  7. Distinctive:

    Verify they fail for the missing implementation.

    line 57
  8. Distinctive:

    Add view-model or UI state tests.

    line 60
  9. Distinctive:

    Run the focused tests and a platform build.

    line 63
  10. Distinctive:

    Keep network out of unit tests.

    line 77
  11. Distinctive:

    Create a small service with pure static helpers and one network method:

    line 82
  12. Very specific:

    Create a @MainActor observable view model for SwiftUI:

    line 159
  13. Distinctive:

    Keep current version and build rows.

    line 206
  14. Distinctive:

    Add a "latest version" or "update" row below them.

    line 207
  15. Very specific:

    Start the check with .task { await viewModel.checkForUpdates() }.

    line 208
  16. Distinctive:

    Do not implement direct binary update installation for App Store apps.

    line 218
  17. Distinctive:

    When adding this feature, platform-specific compile errors elsewhere can block validation.

    line 223
  18. Very specific:

    If withUnsafeBytes warns that the result is unused, assign to _ = when the side effect is intentional.

    line 232
  19. Distinctive:

    Keep these fixes separate from the version-check behavior unless they are needed only to restore the same focused build.

    line 235
  20. Distinctive:

    Run focused tests first:

    line 240
  21. Distinctive:

    If the requested simulator name is unavailable, inspect Xcode's available destinations and rerun with an existing simulator.

    line 270
  22. Very specific:

    Check both ?platform=iphone and ?platform=mac pages before implementing.

    line 296
  23. Distinctive:

    If the app has both TestFlight and App Store channels, explain the distinction: the App Store page reports the public App Store version, …

    line 298
  24. Distinctive:

    Use custom metadata only if TestFlight/latest-beta visibility is explicitly required.

    line 300
  25. Distinctive:

    Always use the App Store product page HTML scraping approach: when you need accurate per-platform versions.

    line 310

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

App Store Version Check

Use this skill when adding update visibility to an iOS, iPadOS, or macOS app. The common goal is: show the current app version, check whether the App Store has a newer public version, and let the user open the App Store or Mac App Store page from the About screen.

Core Decision

Do NOT use the iTunes Lookup API for universal apps that ship separate iOS and Mac App Store builds. The iTunes Lookup API (itunes.apple.com/lookup) only returns the iOS App Store version, even for universal apps that have a different (often older) version on the Mac App Store. The entity=macSoftware parameter does not fix this.

Instead, scrape the App Store product page HTML. The page contains a Version X.Y.Z string in the "What's New" section that reflects the correct per-platform version.

PlatformURL
iOShttps://apps.apple.com/us/app/<name>/id<APP_ID>?platform=iphone
macOShttps://apps.apple.com/us/app/<name>/id<APP_ID>?platform=mac

The platform query parameter selects the correct storefront. The HTML reliably contains Version X.Y.Z (e.g. Version 1.0.6 for Mac, Version 1.1.10 for iOS).

When iTunes Lookup IS acceptable

Only use iTunes Lookup when:

  • The app is iOS-only (no Mac App Store listing).
  • The iOS and Mac App Store versions are always identical (rare for universal apps).
  • You only need the iOS version and don't care about Mac App Store accuracy.

When to use a custom endpoint

Use a custom static JSON endpoint only when the app needs non-App-Store channels such as TestFlight, enterprise distribution, staged rollout metadata, forced minimum version, or release notes not available from Apple.

TDD Workflow

When implementing in a codebase that expects TDD, follow red-green-refactor:

  1. Write pure logic tests first.
  2. Verify they fail for the missing implementation.
  3. Implement the smallest service code.
  4. Verify tests pass.
  5. Add view-model or UI state tests.
  6. Verify they fail.
  7. Implement the About page integration.
  8. Run the focused tests and a platform build.

Good first tests:

  • Version comparison: 1.2.0 is newer than 1.1.11.
  • Same version is not newer.
  • Older App Store version is not an update.
  • Two-part and four-part versions compare correctly.
  • storePageURL(platform:) returns correct platform=iphone / platform=mac URL.
  • parseVersionFromHTML(data:) extracts "1.0.6" from HTML containing Version 1.0.6.
  • parseVersionFromHTML(data:) extracts from localized labels such as 版本 1.0.6.
  • parseVersionFromHTML(data:) extracts from metadata fields like "versionDisplay":"1.0.6".
  • parseVersionFromHTML(data:) returns nil when no version string is present.
  • parseVersionFromHTML(data:) throws malformedResponse on invalid UTF-8 data.

Keep network out of unit tests. Test parsing with HTML string fixtures and inject a mockable service protocol into the view model.

Recommended Swift Structure

Create a small service with pure static helpers and one network method:

struct AppStoreVersionInfo: Equatable {
    let latestVersion: String
    let storeURL: URL
}

enum AppStorePlatform {
    case iOS
    case macOS
}

protocol VersionCheckServiceProtocol: AnyObject {
    func fetchLatestVersion() async throws -> AppStoreVersionInfo
}

final class VersionCheckService: VersionCheckServiceProtocol {
    static let appStoreAppId = "<APP_ID>"

    let platform: AppStorePlatform

    #if os(macOS)
    private static var defaultPlatform: AppStorePlatform { .macOS }
    #else
    private static var defaultPlatform: AppStorePlatform { .iOS }
    #endif

    /// Builds the App Store product-page URL for the given platform.
    static func storePageURL(platform: AppStorePlatform) -> URL {
        let param = platform == .iOS ? "iphone" : "mac"
        return URL(string: "https://apps.apple.com/us/app/<name>/id\(appStoreAppId)?platform=\(param)")!
    }

    /// Extracts the version string from an App Store product-page HTML body.
    /// Tries multiple patterns seen on App Store pages:
    /// `Version X.Y.Z`, `版本 X.Y.Z`, and metadata such as `versionDisplay`.
    static func parseVersionFromHTML(data: Data) throws -> String? {
        guard let html = String(data: data, encoding: .utf8) else {
            throw VersionCheckError.malformedResponse
        }
        let patterns = [
            "(?:Version|版本)\\s*[::]?\\s*(\\d+(?:\\.\\d+){1,3})",
            "\\\"versionDisplay\\\"\\s*:\\s*\\\"(\\d+(?:\\.\\d+){1,3})\\\"",
            "\\\"softwareVersion\\\"\\s*:\\s*\\\"(\\d+(?:\\.\\d+){1,3})\\\""
        ]
        let range = NSRange(html.startIndex..., in: html)
        for pattern in patterns {
            guard let regex = try? NSRegularExpression(pattern: pattern, options: [.caseInsensitive]) else {
                continue
            }
            if let match = regex.firstMatch(in: html, range: range),
               match.numberOfRanges >= 2,
               let versionRange = Range(match.range(at: 1), in: html) {
                return String(html[versionRange])
            }
        }
        return nil
    }

    static func isVersion(_ latest: String, newerThan current: String) -> Bool {
        let latestParts = latest.split(separator: ".").compactMap { Int($0) }
        let currentParts = current.split(separator: ".").compactMap { Int($0) }
        let count = max(latestParts.count, currentParts.count)

        for index in 0..<count {
            let latestPart = index < latestParts.count ? latestParts[index] : 0
            let currentPart = index < currentParts.count ? currentParts[index] : 0
            if latestPart > currentPart { return true }
            if latestPart < currentPart { return false }
        }

        return false
    }
}

Create a @MainActor observable view model for SwiftUI:

enum VersionCheckState: Equatable {
    case idle
    case checking
    case upToDate(latestVersion: String)
    case updateAvailable(info: AppStoreVersionInfo)
    case failed(String)
}

@MainActor
final class VersionCheckViewModel: ObservableObject {
    @Published var state: VersionCheckState = .idle

    var service: VersionCheckServiceProtocol
    var currentVersion: String

    var updateURL: URL? {
        if case .updateAvailable(let info) = state {
            return info.storeURL
        }
        return nil
    }

    init(currentVersion: String, service: VersionCheckServiceProtocol) {
        self.currentVersion = currentVersion
        self.service = service
    }

    func checkForUpdates() async {
        state = .checking
        do {
            let info = try await service.fetchLatestVersion()
            state = VersionCheckService.isVersion(info.latestVersion, newerThan: currentVersion)
                ? .updateAvailable(info: info)
                : .upToDate(latestVersion: info.latestVersion)
        } catch {
            state = .failed(error.localizedDescription)
        }
    }
}

SwiftUI About Page Pattern

On the About page:

  • Keep current version and build rows.
  • Add a "latest version" or "update" row below them.
  • Start the check with .task { await viewModel.checkForUpdates() }.
  • For .checking, show a progress indicator or "checking..." text.
  • For .updateAvailable, show the latest version and an "Update" button.
  • Open trackViewUrl via @Environment(\.openURL).
  • For .upToDate, show a neutral "No update available" message. If the local version is ahead of App Store (common after local/TestFlight builds), avoid saying "latest App Store version" in a misleading way.
  • For .failed, show a short non-blocking error reason (for example 429) and a retry button on the same row. Keep the message concise with truncation.

Do not implement direct binary update installation for App Store apps. Opening Apple's store URL is the correct fallback and usually the right behavior.

Platform Build Pitfalls

When adding this feature, platform-specific compile errors elsewhere can block validation. Fix them narrowly when they are real platform API issues:

  • FileManager.default.homeDirectoryForCurrentUser is unavailable on iOS. Use a sandbox-safe fallback such as Application Support on iOS, and keep homeDirectoryForCurrentUser behind #if os(macOS) if needed.
  • SecCertificateCopyValues, kSecOIDX509V1ValidityNotAfter, and kSecPropertyKeyValue are macOS-oriented Security APIs. Guard certificate value parsing with #if os(macOS) or provide an iOS-safe alternative.
  • If withUnsafeBytes warns that the result is unused, assign to _ = when the side effect is intentional.

Keep these fixes separate from the version-check behavior unless they are needed only to restore the same focused build.

Validation

Run focused tests first:

xcodebuild test \
  -scheme <SCHEME> \
  -project <PROJECT>.xcodeproj \
  -destination 'platform=macOS' \
  -only-testing:<TestTarget>/VersionCheckServiceTests

Then run About/view-model tests:

xcodebuild test \
  -scheme <SCHEME> \
  -project <PROJECT>.xcodeproj \
  -destination 'platform=macOS' \
  -only-testing:<TestTarget>/AboutViewVersionCheckTests

Finally run at least one target platform build, usually iOS Simulator for a universal app:

xcodebuild build \
  -scheme <SCHEME> \
  -project <PROJECT>.xcodeproj \
  -destination 'platform=iOS Simulator,name=<AVAILABLE_DEVICE>'

If the requested simulator name is unavailable, inspect Xcode's available destinations and rerun with an existing simulator.

For a live sanity check of the per-platform version:

# iOS App Store version
curl -fsSL 'https://apps.apple.com/us/app/<name>/id<APP_ID>?platform=iphone' | grep -oE 'Version [0-9]+\.[0-9]+\.[0-9]+' | head -1

# Mac App Store version
curl -fsSL 'https://apps.apple.com/us/app/<name>/id<APP_ID>?platform=mac' | grep -oE 'Version [0-9]+\.[0-9]+\.[0-9]+' | head -1

Confirm the two platforms return different versions if the app ships separate builds.

Source of Truth Checklist

Before coding, locate:

  • App Store app ID in CI config, marketing metadata, or App Store links.
  • Bundle current version from CFBundleShortVersionString.
  • Bundle build number from CFBundleVersion.
  • Existing About page implementation.
  • Existing test style and platform destinations.

Critical: verify per-platform versions independently. For universal apps, the iOS App Store and Mac App Store often have different version numbers. Check both ?platform=iphone and ?platform=mac pages before implementing.

If the app has both TestFlight and App Store channels, explain the distinction: the App Store page reports the public App Store version, not TestFlight. Use custom metadata only if TestFlight/latest-beta visibility is explicitly required.

Key Lesson: iTunes Lookup API Limitation

The iTunes Lookup API (itunes.apple.com/lookup) is not reliable for Mac App Store version checking on universal apps. It returns the iOS App Store version regardless of the entity parameter. The entity=macSoftware parameter does not fix this.

Always use the App Store product page HTML scraping approach when you need accurate per-platform versions. The platform=mac vs platform=iphone query parameter on the App Store web page is the only reliable way to get the correct version for each platform.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.