This document describes how to set up the Crossbar home screen widget on iOS using Xcode.
- macOS with Xcode 14+ installed
- iOS deployment target: 14.0+
- Apple Developer Account (for testing on physical devices)
- Open the iOS project in Xcode:
open ios/Runner.xcworkspace - Go to File → New → Target
- Select Widget Extension
- Configure:
- Product Name:
CrossbarWidget - Team: Your team
- Include Configuration Intent: No (we use StaticConfiguration)
- Product Name:
- Click Finish
Both the main app (Runner) and the widget extension need to share data via App Groups.
- Select Runner target
- Go to Signing & Capabilities
- Click + Capability → App Groups
- Add group:
group.crossbar.widgets
- Select CrossbarWidget target
- Go to Signing & Capabilities
- Click + Capability → App Groups
- Add the same group:
group.crossbar.widgets
- Delete the auto-generated
CrossbarWidget.swiftin the widget target - Copy the content from
ios/CrossbarWidget/CrossbarWidget.swift(this file) to the target
In the CrossbarWidget/Info.plist, ensure:
<key>NSWidgetKind</key>
<string>com.apple.HomeWidget</string>- Select the Runner scheme
- Build and run on a device/simulator with iOS 14+
- Long-press on home screen → Add Widget → Find "Crossbar Plugin"
- Ensure App Groups are configured correctly on both targets
- Check that the
appGroupIdinCrossbarWidget.swiftmatches (group.crossbar.widgets) - Make sure the Flutter app has saved data at least once
- Clean build folder: Product → Clean Build Folder
- Rebuild the project
- On simulator: Reset Content and Settings
- The widget refreshes every 30 minutes by default
- To force update, remove and re-add the widget
- Or call
WidgetCenter.shared.reloadAllTimelines()from the app
┌─────────────────┐ ┌─────────────────┐
│ Flutter App │────▶│ UserDefaults │
│ (Runner) │ │ (App Group) │
└─────────────────┘ └────────┬────────┘
│
▼
┌─────────────────────┐
│ CrossbarWidget │
│ (Widget Extension) │
└─────────────────────┘
The Flutter app saves data in the following format:
// Key: "plugin_ids"
["cpu.10s.sh", "memory.10s.sh", "battery.30s.sh"]
// Key: "plugin_cpu.10s.sh"
{
"pluginId": "cpu.10s.sh",
"text": "45%",
"icon": "⚡",
"color": "FF5733",
"tooltip": "Current CPU usage"
}The widget reads this data via UserDefaults(suiteName: "group.crossbar.widgets").