Files
swiftcontrol/ios/TrainerActivity/TrainerActivityAttributes.swift
Jonas Bark f098f5c7bf ios: align extension Swift with the working live_activities example
Two structural fixes after diffing against the package's working example:
- Revert ContentState to empty. The plugin's createActivity calls a
  ContentState() constructor with no args from the example pattern; the
  appGroupId field was a red herring from the plugin's internal type.
- Switch the widget's @available marker from iOS 16.1 to
  iOSApplicationExtension 16.1, the correct platform key for an app
  extension target. iOS 16.1 was being honored at compile time but the
  WidgetKit registration uses the extension-specific availability scope.
- Inline the field reads inside the widget closures (matches the example
  layout) instead of routing through a helper struct.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 15:37:28 +02:00

24 lines
744 B
Swift

import ActivityKit
import Foundation
// The `live_activities` Flutter plugin always launches activities of this
// exact type. Field data is NOT encoded into ContentState — the plugin
// writes each entry into the App Group's UserDefaults keyed by
// `<id>_<fieldName>` and the widget reads them back via
// `attributes.prefixedKey(...)`.
//
// ContentState is intentionally empty to match the package's example.
struct LiveActivitiesAppAttributes: ActivityAttributes, Identifiable {
public typealias LiveDeliveryData = ContentState
public struct ContentState: Codable, Hashable {}
var id = UUID()
}
extension LiveActivitiesAppAttributes {
func prefixedKey(_ key: String) -> String {
return "\(id)_\(key)"
}
}