$npx -y skills add dpearson2699/swift-ios-skills --skill relevancekitIncrease widget visibility on Apple Watch using RelevanceKit. Use when providing contextual relevance signals for watchOS widgets, declaring time-based or location-based relevance, combining multiple relevance providers, helping the system surface the right widget at the right ti
| 1 | # RelevanceKit |
| 2 | |
| 3 | Provide on-device contextual clues that increase a widget's visibility in the |
| 4 | Apple Watch Smart Stack. RelevanceKit tells the system *when* a widget is |
| 5 | relevant by time, location, fitness state, sleep schedule, or connected hardware. |
| 6 | Targets Swift 6.3 / watchOS 26+. |
| 7 | |
| 8 | > **Beta-sensitive.** Re-check Apple documentation before making strong RelevanceKit availability or behavior claims. |
| 9 | |
| 10 | See [references/relevancekit-patterns.md](references/relevancekit-patterns.md) for complete relevant-widget, timeline provider, grouping, preview, and permission patterns. |
| 11 | |
| 12 | ## Contents |
| 13 | |
| 14 | - [Overview](#overview) |
| 15 | - [Setup](#setup) |
| 16 | - [Relevance Providers](#relevance-providers) |
| 17 | - [Boundary Routing](#boundary-routing) |
| 18 | - [Time-Based Relevance](#time-based-relevance) |
| 19 | - [Location-Based Relevance](#location-based-relevance) |
| 20 | - [Fitness and Sleep Relevance](#fitness-and-sleep-relevance) |
| 21 | - [Hardware Relevance](#hardware-relevance) |
| 22 | - [Combining Signals](#combining-signals) |
| 23 | - [Widget Integration](#widget-integration) |
| 24 | - [Common Mistakes](#common-mistakes) |
| 25 | - [Review Checklist](#review-checklist) |
| 26 | - [References](#references) |
| 27 | |
| 28 | ## Overview |
| 29 | |
| 30 | watchOS uses two mechanisms to determine widget relevance in the Smart Stack: |
| 31 | |
| 32 | 1. **Timeline provider relevance** -- implement `relevance()` on an existing |
| 33 | `AppIntentTimelineProvider` to attach `RelevantContext` clues to timeline |
| 34 | entries. Available across platforms; only watchOS acts on the data. |
| 35 | 2. **Relevant widget** -- use `RelevanceConfiguration` with a |
| 36 | `RelevanceEntriesProvider` to build a widget driven entirely by relevance |
| 37 | clues. The system creates individual Smart Stack cards per relevant entry. |
| 38 | watchOS 26+ only. |
| 39 | |
| 40 | Choose a timeline provider when the widget always has data to show and relevance |
| 41 | is supplementary. Choose a relevant widget when the widget should *only* appear |
| 42 | when conditions match, or when multiple cards should appear simultaneously (e.g., |
| 43 | several upcoming calendar events). |
| 44 | |
| 45 | ### Key Types |
| 46 | |
| 47 | | Type | Module | Role | |
| 48 | |---|---|---| |
| 49 | | `RelevantContext` | RelevanceKit | A contextual clue (date, location, fitness, sleep, hardware) | |
| 50 | | `WidgetRelevance` | WidgetKit | Collection of relevance attributes for a widget kind | |
| 51 | | `WidgetRelevanceAttribute` | WidgetKit | Pairs a widget configuration with a `RelevantContext` | |
| 52 | | `WidgetRelevanceGroup` | WidgetKit | Controls grouping behavior in the Smart Stack | |
| 53 | | `RelevanceConfiguration` | WidgetKit | Widget configuration driven by relevance clues (watchOS 26+) | |
| 54 | | `RelevanceEntriesProvider` | WidgetKit | Provides entries for a relevance-configured widget (watchOS 26+) | |
| 55 | | `RelevanceEntry` | WidgetKit | Data needed to render one relevant widget card (watchOS 26+) | |
| 56 | |
| 57 | `RelevanceConfiguration`, `RelevanceEntriesProvider`, and `RelevanceEntry` are |
| 58 | WidgetKit APIs. Keep them in this skill's scope only when they are part of the |
| 59 | watchOS relevant-widget workflow that exposes RelevanceKit clues. |
| 60 | |
| 61 | ## Setup |
| 62 | |
| 63 | ### Import |
| 64 | |
| 65 | ```swift |
| 66 | import RelevanceKit |
| 67 | import WidgetKit |
| 68 | ``` |
| 69 | |
| 70 | ### Platform Availability |
| 71 | |
| 72 | `RelevantContext` is declared across platforms (iOS 17+, watchOS 10+), but |
| 73 | **RelevanceKit functionality only takes effect on watchOS**. Calling the API on |
| 74 | other platforms has no effect. Timeline-provider `relevance()` is available on |
| 75 | iOS 18+, macOS 15+, visionOS 26+, and watchOS 11+ for shared provider code. |
| 76 | `RelevanceConfiguration`, `RelevanceEntriesProvider`, and `RelevanceEntry` are |
| 77 | watchOS 26+ only. |
| 78 | |
| 79 | ### Permissions |
| 80 | |
| 81 | Certain relevance clues require authorization or target setup: |
| 82 | |
| 83 | | Clue | Required Permission | |
| 84 | |---|---| |
| 85 | | `.location(inferred:)` | Containing app requests location access; widget extension declares `NSWidgetWantsLocation` | |
| 86 | | `.location(_:)` (CLRegion) | Containing app requests location access; widget extension declares `NSWidgetWantsLocation` | |
| 87 | | `.location(category:)` | Containing app requests location access; widget extension declares `NSWidgetWantsLocation` | |
| 88 | | `.fitness(.workoutActive)` | HealthKit access to `HKWorkoutType` | |
| 89 | | `.fitness(.activityRingsIncomplete)` | HealthKit access to `appleExerciseTime`, `appleMoveTime`, and `appleStandTime` | |
| 90 | | `.sleep(_:)` | HealthKit `sleepAnalysis` permission | |
| 91 | | `.hardware(headphones:)` | None | |
| 92 | | `.date(...)` | None | |
| 93 | |
| 94 | Add location purpose strings to the containing app's `Info.plist`, not only the |
| 95 | widget extension. In widget code, check `CLLocationManager.isAuthorizedForWidgetUpdates` |
| 96 | before relying on location clues. For fitness and sleep clues, enable HealthKit |
| 97 | and request the exact read types in the app and widget extension target that |
| 98 | provides relevance. |
| 99 | |
| 100 | ## Relevance P |