SwiftNEW Framework

repository·main·Indexed 42 days ago

https://github.com/1998code/swiftnewkit

A SwiftUI-native framework for presenting 'What's New' release notes and update screens across Apple platforms, including iOS, watchOS, macOS, tvOS, visionOS, and CarPlay. It supports local and remote JSON data sources, version tracking via App Storage, and remote update checks using the Apple iTunes Lookup API. For CarPlay, it provides a CPListTemplate adapter and a SwiftNEWCarPlayTemplateFactory to manage native templates and scene lifecycles.

Tokens
14.2K
Snippets
23
Records
48
Agent score
51%

What's inside SwiftNEW

  1. CarPlay Integration Scope and Safety Constraints

    main

    When integrating SwiftNEW with CarPlay, adhere to the following architectural constraints to ensure compliance with Apple's guidelines:

    • Template Type: The adapter uses CPListTemplate rather than CPInformationTemplate or SwiftUI. This ensures compatibility across a wider range of eligible template-app categories.
    • Hierarchy Limits: To stay within the strict two-level hierarchy allowed for quick-ordering apps, the 'What's New' content acts as the root, and selected details act as the second level.
    • History Implementation: Historical data is displayed using CPListTemplate.updateSections(_:) on the existing root rather than pushing a new template, preserving the two-level limit.
    • UI Limitations: A phone's SwiftUI ContentView cannot be rendered on a CarPlay display. The Continue callback must replace the SwiftNEW root with a native CPTemplate.
    • Interaction: The Continue button is implemented as a CPBarButton to avoid consuming the runtime list-item allowance.
  2. Understand Auto-Trigger Storage

    main

    SwiftNEW tracks which versions have already been shown to the user using @AppStorage. This prevents the same release notes from appearing repeatedly. It uses the following namespaced keys:

    KeyValue
    swiftnew.versionLast displayed CFBundleShortVersionString
    swiftnew.buildLast displayed CFBundleVersion

    Comparison is string-safe, supporting non-numeric values like 1.0-beta.

  3. CarPlay Integration Requirements and Safety

    main

    CarPlay is a managed capability.

    • Approval Required: Apple must approve the host app for an eligible CarPlay category before this integration can run on a device or be submitted to the App Store.
    • Content Eligibility: The content shown must belong to the approved category and be useful while driving. A general product changelog or developer-tools app is not eligible simply because the host app has a CarPlay entitlement.
    • Entitlement Scope: Do not attempt to use unrelated audio or navigation entitlements to bypass these requirements.
  4. How remote updates and `checkForUpdates` work

    main

    When you set checkForUpdates: true and provide a remote data URL, SwiftNEW performs a version check:

    1. It compares the highest subVersion (or version) found in the remote JSON against the currently installed app version.
    2. If the remote version is newer, SwiftNEW displays an Update Screen instead of the standard release notes.
    3. The update screen uses Apple's iTunes Lookup API to find the App Store destination using your app's bundle identifier.
    4. The primary action button defaults to a localized 'Download Now' text, but you can customize this using updateButtonTitle.
    5. To force users to update, set allowsSkippingUpdate: false.
  5. Configure Remote Update Checks

    main

    SwiftNEW can automatically check for updates by providing a remote data URL and setting checkForUpdates: true.

    If the highest subVersion (or version) in the remote JSON is newer than the installed app version, SwiftNEW will display an Update Screen instead of the standard 'What's New' screen. It uses the App Store's iTunes Lookup API to find the target app using your bundle identifier.

    Key behaviors:

    • Default Button: Displays a localized "Download Now" button.
    • Custom Button: Use updateButtonTitle to provide custom text.
    • Enforced Updates: Set allowsSkippingUpdate: false if you want to prevent users from skipping the update screen.
  6. Enable Remote Update Checks and App Store Redirection

    main

    You can enable a remote update flow by passing a remote data URL and setting checkForUpdates: true.

    Behavior:

    • If the highest subVersion (or version) in the remote JSON is greater than the current installed app version, SwiftNEW will display an Update Screen instead of the standard 'What's New' screen.
    • The update screen uses the app's bundle identifier to automatically fetch the App Store destination via the Apple iTunes Lookup API.
    • The primary action button defaults to a localized 'Download Now' (or equivalent). You can customize this text using updateButtonTitle.
    • To force users to update, set allowsSkippingUpdate: false to prevent them from dismissing the update screen.
  7. Enable Remote Update Checks

    main

    If you provide a remote data URL and set checkForUpdates: true, SwiftNEWKit will automatically check for updates.

    If the highest subVersion (or version if subVersion is missing) in the remote JSON is higher than the installed app version, SwiftNEWKit will display an update screen instead of the standard

  8. How SwiftNEW handles version tracking and updates

    main

    SwiftNEW manages versioning and update checks using the following logic:

    Version Tracking

    SwiftNEW tracks the last-seen version and build using namespaced App Storage keys:

    • swiftnew.version
    • swiftnew.build

    Version comparison is string-safe, supporting non-numeric values like 1.0-beta or 1.0b3 without crashing.

    Remote Update Checks

    By passing checkForUpdates: true along with a remote data URL, SwiftNEW will compare the highest remote subVersion (or version) against the installed app version.

    If a newer version is found:

    • It presents an Update screen instead of the standard "What's New" screen.
    • It resolves the App Store destination using the Apple iTunes Lookup API via your app's bundle identifier.
    • The primary action defaults to a localized Download Now button (customizable via updateButtonTitle).
    • You can prevent users from bypassing this by setting allowsSkippingUpdate: false.
  9. Enable remote update checking

    main

    You can configure SwiftNEW to check for remote updates by setting checkForUpdates: true and providing a remote data URL.

    How it works:

    1. SwiftNEW compares the highest subVersion (or version) in the remote JSON with the currently installed app version.
    2. If the remote version is newer, it displays an update screen instead of the standard release notes.
    3. It automatically fetches the App Store destination using Apple's iTunes Lookup API via your app's bundle identifier.

    Customization:

    • Use updateButtonTitle to change the text of the primary action (defaults to a localized "Download Now").
    • Set allowsSkippingUpdate: false to force users to update before they can proceed.
  10. Configure Icon Animations and Transitions

    main

    SwiftNEW supports two ways to animate icons within a release note entry:

    1. Replace Transition: Use icon and toIcon to define a single transition from one symbol to another.
    2. Symbol Loop: Use the icons array to loop through a sequence of symbols.

    If icons is provided, it takes precedence over icon and toIcon.

    // Replace Transition
    {
      "icon": "checkmark.shield",
      "toIcon": "shield.checkered",
      "title": "Compatibility",
      "subtitle": "Fixes",
      "body": "Improved platform support."
    }
    
    // Symbol Loop
    {
      "icons": ["checkmark.shield", "shield.checkered", "sparkles"],
      "title": "Compatibility",
      "subtitle": "Fixes",
      "body": "Improved platform support."
    }
  11. How CarPlay integration works in SwiftNEW

    main

    SwiftNEW provides an iOS-only CPListTemplate adapter for approved CarPlay host apps. This adapter converts the same local or remote JSON format used by the SwiftUI view into system CarPlay templates.

    Key Behaviors:

    • Version Matching: The current release is shown by default if the JSON contains an exact match for the installed version.
    • Change Details: Each change opens a second list containing its full description.
    • History Mode: Setting includesHistory: true in the JSON adds a History button. This button toggles the root list between the current release and older releases.
    • Continue Button: Loading and loaded templates can expose a trailing Continue button (supplied by the host app). Clicking Continue replaces the release-note root with the host app's native CarPlay content template.
    • SF Symbols: Row icons are pre-rasterized as system-blue light/dark bitmaps at the CarPlay display scale to ensure they render correctly as system templates rather than black glyphs.
    • Constraints: Runtime sections and item limits are automatically respected. Opening a CarPlay template does not modify SwiftNEW's seen-version state.
  12. Configure SwiftNEW for watchOS

    main

    On watchOS, SwiftNEW automatically uses compact layouts for the current version, history, and update screens.

    Key behaviors:

    • Space Saving: Release-note descriptions and Search controls are hidden by default. To enable them, pass showDescription: true or search: true.
    • Visuals: watchOS 8–9 use solid fallbacks for Material backgrounds. watchOS 10 adds Material backgrounds, and watchOS 11 adds native MeshGradient. Older versions use a layered gradient fallback.
    • Performance: Animation particle counts and liquid-mesh refresh rates are automatically reduced for Apple Watch.

    Companion App Setup:

    • SwiftNEW automatically uses WKCompanionAppBundleIdentifier if present.
    • Use appStoreBundleIdentifier only if you need to explicitly override the App Store listing identifier.
    • Important: Local data.json files must be included in the Watch target itself.