(I truly appreciate all the responses you all have written for me :bow: )
I was under the assumption that for Live Activity, in order for you to be able to update the Activity, you need an update token. And for the OS to issue you the update token, user must hit the "Allow" from the lock screen.
However based on these screenshots it seems that you don't need to hit "Allow" to be able to update the Live Activity.
Live Activity was updated — even without the user hitting "Allow"
So now I'm wondering if:
Is hitting Allow required for the update token to get issued? Or that assumption is incorrect? In our tests (when connected to Proxyman, the OS emits the update token after user hits "Allow" / "Always Allow")
If you don't hit allow, are there alternate ways to update the Live Activity without having the update token?
I'm guessing you could set a short stale time and then when the OS launches the app in the background you query the server and then update the Live Activity. Is that a worthy approach?
I also noticed that the "The Philly Inquirer" App has 'Background App Refresh" enabled, but this happened in 2 minutes. In our architecture assessments, after reviewing Apple's docs on 'Background Processing", we didn't think of it as a viable option, because it can't guarantee if the OS is given time in the next 2 minutes or 10 hours later when the phone is getting charged again.
Are any of these workarounds viable or are there alternate approaches?
Our requirement is:
be able to use Live Activity between 2-72hrs after app install. (I mention this because perhaps Apple may impost some restrictions for new installs)
be able to update an active Live Activity within 1-2 minutes after it has began.
Widgets & Live Activities
RSS for tagDiscuss how to manage and implement Widgets & Live Activities.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
We are using the MPNowPlayingInfoCenter API to provide information to the “Now Playing” system UI. This works as expected, except that when the app is manually terminated, the information is removed from the UI.
Our question is: Some apps (for example, Audible) are able to appear in the “Recently Played” section of the UI. This section seems to show a history of apps that previously provided “Now Playing” information but are not currently playing anything.
We would like to know which API is used to achieve this behavior.
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Hi,
We design a Live Activity for our app.We find that in iOS26 system, the widget can not display the correct system display model(Light mode or dark mode), always display with dark mode. When our app run in other system ,such as iOS 17, iOS18 ,it work fine.
I find other developer had post a topic three month ago , but it seems there is not any new response about the feedback.
https://developer.apple.com/forums/thread/799684?answerId=857377022#857377022
Anyone have idea?
Thanks .
Below is my code template:
struct BroadcastLiveActivityBackgroundView: View {
@Environment(\.colorScheme) var colorScheme: ColorScheme
var body:some View {
LinearGradient(
stops: [
Gradient.Stop(color: LiveActivityColor.backgroundColors(self.colorScheme).last!, location: 0.00),
Gradient.Stop(color: LiveActivityColor.backgroundColors(self.colorScheme).first!, location: 1.00),
],
startPoint: UnitPoint(x: 1, y: 0),
endPoint: UnitPoint(x: 0.82, y: 1.11)
)
}
}
I want to make a app that indicates that the app is recording in the background using a indicator on the dynamic island or on the top of the phone screen but i can't figure it out on Xcode. Saw a guy do it by making live activities true but can't seem to find that option in background mode in capabilities. any ideas?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Subject: Request to maintain the "Status Bar Breadcrumb" visibility while Dynamic Island is active
Hi,
I am developing an app using ActivityKit and Dynamic Island. I've noticed a significant UX regression regarding the system status bar behavior.
Current Behavior: When a Live Activity is active in the Dynamic Island (specifically in the compactLeading and compactTrailing presentation), the system automatically hides the "Back to [Previous App]" breadcrumb button (the small arrow and app name) in the top-left corner of the status bar.
This breadcrumb only reappears when the Live Activity switches to the minimal presentation or is dismissed.
The Issue: This behavior makes multitasking cumbersome for users. For example, if a user navigates from Safari to my app and then locks the screen or goes to Home, they expect the "Back to Safari" button to remain accessible. However, because my app's Live Activity is running in the Dynamic Island, the OS removes this navigation shortcut, forcing users to use the app switcher instead.
Why this should be changed:
Screen Real Estate: On larger devices (e.g., iPhone 15/16 Pro Max), there is significant whitespace in the top-left corner between the time and the Dynamic Island's leading edge. The breadcrumb could easily fit there without overlapping the Live Activity content.
Inconsistent UX: Users are confused why the navigation button disappears solely because a background activity is running.
Request: Please consider updating the status bar layout logic to allow the "Back to App" breadcrumb to remain visible if there is no physical overlap with the compactLeading view of the Dynamic Island.
Thank you.
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Since watchOS 26, watch face sharing has stopped working completely.
I tested the following:
Sharing via CLKWatchFaceLibrary
Other public APIs
Sharing via iMessage
In all cases, the watch face cannot be reinstalled after being shared.
This issue is not limited to my app. Large third-party apps such as Facer and other major watch face platforms are also affected, which suggests this is a system-level change or bug.
Everything worked correctly before watchOS 26.
Has Apple officially acknowledged this issue?
Is there a recommended place to report or track this bug?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
Face Sharing
watchOS
Watch Complications
WidgetKit
Issue Description:
Tapping the app widget sometimes triggers the Universal Link twice, causing duplicate navigation or actions within the app
Steps to Reproduce:
Add the app widget to the home screen
Tap the widget to open the app via the Universal Link
Observe that the Universal Link is sometimes fired twice
Expected Behavior:
Tapping the widget should trigger the Universal Link only once.
Actual Behavior:
Universal Link is triggered twice, causing duplicate
navigation or actions.
Summary
A crash occurs in ViewBridge framework when a TUINSRemoteViewController object
receives -release message after being deallocated. This appears to be a
reference counting issue within the ViewBridge framework's internal
autorelease pool management.
Environment
macOS Version: [15.0.0]
Application: Custom Qt-based application using Chromium Embedded Framework (xcode version: xcode 15; QT version: 6.5.4 ; CEF version: 138.0.47+g2728d53+chromium-138.0.7204.221)
Steps to Reproduce
Users are typically using the app normally, but a crash occasionally occurs when they activate and click on the application. This happens infrequently, but it occurs roughly every day. Currently, only a few specific users experience this crash, and it may appear for several consecutive days before disappearing for several days.
We cannot reliably reproduce this issue but have collected crash logs
from affected users.
Crash Analysis
Zombie Detection Log:
Zombie <TUINSRemoteViewController: 0x338708020> received -release
Deallocation Stack Trace (when object was first released):
0 Chromium Embedded Framework 0x000000014283a7f4 rust_png$cxxbridge1$ResultOfWriter$operator$sizeof + 933592
1 AppKit 0x000000019eac0d80 -[NSResponder dealloc] + 340
2 AppKit 0x000000019ebb5e34 -[NSViewController dealloc] + 276
3 ViewBridge 0x00000001a3f6ab9c -[NSRemoteViewController dealloc] + 92
4 AppKit 0x000000019eada4b4 -[NSViewController release] + 236
5 ViewBridge 0x00000001a3eda130 -[NSRemoteViewController release] + 380
6 libobjc.A.dylib 0x000000019aa8806c objc_autoreleasePoolPop + 56
7 CoreFoundation 0x000000019aefc7c0 _CFAutoreleasePoolPop + 32
8 Foundation 0x000000019c0d14f4 -[NSAutoreleasePool drain] + 136
9 ViewBridge 0x00000001a3ed609c __CONSIDER_WHO_REQUESTED_THIS_WAIT_BEFORE_SENDING_BUG_TO_VIEWBRIDGE__ + 24
10 ViewBridge 0x00000001a3f82a10 deferredBlockOpportunity_block_invoke_2 + 436
11 CoreFoundation 0x000000019af3dfa0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28
12 CoreFoundation 0x000000019af3deb0 __CFRunLoopDoBlocks + 356
13 CoreFoundation 0x000000019af3d330 __CFRunLoopRun + 2432
14 CoreFoundation 0x000000019af3c334 CFRunLoopRunSpecific + 572
15 HIToolbox 0x00000001a63740cc RunCurrentEventLoopInMode + 292
16 HIToolbox 0x00000001a6379ebc ReceiveNextEventCommon + 636
17 HIToolbox 0x00000001a637a020 _BlockUntilNextEventMatchingListInModeWithFilter + 76
18 AppKit 0x000000019ea7fa70 _DPSNextEvent + 660
19 AppKit 0x000000019f3a57b8 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 688
Crash Stack Trace (second release attempt):
0 Chromium Embedded Framework 0x14a03a37c rust_png$cxxbridge1$ResultOfWriter$operator$sizeof + 932448
1 Chromium Embedded Framework 0x14a03a04c rust_png$cxxbridge1$ResultOfWriter$operator$sizeof + 931632
2 CoreFoundation 0x19af1cbe8 ___forwarding___ + 200
3 CoreFoundation 0x19af1ca60 _CF_forwarding_prep_0 + 96
4 libobjc.A.dylib 0x19aa8bd94 AutoreleasePoolPage::releaseUntil(objc_object**) + 204
5 libobjc.A.dylib 0x19aa88138 objc_autoreleasePoolPop + 260
6 CoreFoundation 0x19aefc7c0 _CFAutoreleasePoolPop + 32
7 Foundation 0x19c0d14f4 -[NSAutoreleasePool drain] + 136
8 ViewBridge 0x1a3ed609c __CONSIDER_WHO_REQUESTED_THIS_WAIT_BEFORE_SENDING_BUG_TO_VIEWBRIDGE__ + 24
9 ViewBridge 0x1a3f82a10 deferredBlockOpportunity_block_invoke_2 + 436
10 CoreFoundation 0x19af3dfa0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28
11 CoreFoundation 0x19af3deb0 __CFRunLoopDoBlocks + 356
12 CoreFoundation 0x19af3d330 __CFRunLoopRun + 2432
13 CoreFoundation 0x19af3c334 CFRunLoopRunSpecific + 572
14 HIToolbox 0x1a63740cc RunCurrentEventLoopInMode + 292
15 HIToolbox 0x1a6379ebc ReceiveNextEventCommon + 636
16 HIToolbox 0x1a637a020 _BlockUntilNextEventMatchingListInModeWithFilter + 76
17 AppKit 0x19ea7fa70 _DPSNextEvent + 660
18 AppKit 0x19f3a57b8 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 688
19 AppKit 0x19ea72b7c -[NSApplication run] + 480
20 libqcocoa.dylib 0x1057b7514 QCocoaEventDispatcher::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 2156
21 QtCore 0x109bb55c4 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 532
22 QtCore 0x109babff8 QCoreApplication::exec() + 112
23 HoYowave 0x1009fc740 QWidgetFrameAdapter::RunMessageLoop() + 132
24 HoYowave 0x1008ae908 0x10088c000 + 141576
25 HoYowave 0x1008b7038 0x10088c000 + 176184
26 HoYowave 0x1008a3544 0x10088c000 + 95556
27 HoYowave 0x1008a294c 0x10088c000 + 92492
28 dyld 0x19aad4274 start + 2840
Technical Analysis
The crash pattern indicates:
A TUINSRemoteViewController was autoreleased multiple times
During autorelease pool drain, the first release triggered dealloc
Subsequent release attempts accessed the deallocated object (zombie)
This is entirely within ViewBridge framework's internal code path
The function name __CONSIDER_VIEW_SERVICE_BEFORE_SENDING_BUG_TO_VIEWBRIDGE__
in the stack trace suggests this is a known problematic area.
Questions
Is this a known issue in ViewBridge framework?
Is there any workaround or mitigation we can apply from the application side?
Could you provide guidance on what might trigger this condition?
I have report this in Feedback Assistant FB21809243
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Hello Apple Developer Technical Support,
I’m following up on case #102807413324 and submitting this as a code-level support request.
We are integrating iOS Live Activities (ActivityKit + WidgetKit extension written in SwiftUI) into an Expo/React Native app. We’re seeing behavior where the Live Activity UI shown on the Lock Screen appears to “stick” to an older layout and ignores updated SwiftUI code and/or bundled assets, even after rebuilding, reinstalling, and removing existing Live Activities before testing again.
Environment
Device: iPhone 13
iOS: 26.2
macOS: 15.7.3 (24G419)
Xcode: 16.4 (16F6)
Expo SDK: 52
React Native: 0.76.9
expo-live-activity: ^0.4.2
Build type: Ad-Hoc signed IPA (EAS local build)
Summary
We have a WidgetKit extension target (LiveActivity.appex, bundle id: stimul8.LiveActivity) using ActivityConfiguration(for: LiveActivityAttributes.self).
The extension contains multiple SwiftUI views selected via a “route” (derived from deepLinkUrl / title / subtitle), and uses images/backgrounds from the extension asset catalog (Assets.xcassets). We also support loading images from an App Group container with a fallback to the asset catalog.
After shipping updates, the Live Activity UI shown on the Lock Screen continues to resemble an older/default layout (example: a progress-bar-like element remains visible even after removing ProgressView usage from LiveActivityView.swift). Some custom backgrounds/images also fail to display as expected.
Routing (examples)
/streak -> StreakLiveActivityView
/streak-urgent -> StreakUrgentLiveActivityView
/lesson/create -> AILessonLiveActivityView1
/lesson/reminder -> AILessonLiveActivityView2
default -> LiveActivityView
Steps to reproduce (high-level)
Install/build and trigger a Live Activity.
Modify the SwiftUI layout in the extension (e.g., remove ProgressView and change obvious UI elements), rebuild, and reinstall.
Remove any existing Live Activities from the Lock Screen, then trigger a new Live Activity again.
Observed: Lock Screen Live Activity still renders the prior/older-looking UI and/or ignores updated assets.
Troubleshooting already done
Verified the extension (LiveActivity.appex) is included in the IPA and properly signed.
Verified Assets.car is present in the extension and PNG assets are present in the build artifacts.
Ensured SwiftUI source files used by the extension are overwritten during prebuild so the intended versions are present in ios/LiveActivity.
Cleared DerivedData related to LiveActivity builds.
Reinstalled the app and removed existing Live Activities from the Lock Screen before re-triggering new ones.
Questions
Is there any known caching behavior where Live Activities can continue to display a previous UI layout after an app/extension update, even when the activity is re-created?
Are there recommended steps to force the system to load the newest widget extension binary/UI beyond reinstalling and removing existing Live Activities?
What’s the recommended way to confirm which exact extension binary/UI version is being rendered on-device (e.g., specific Console logs, sysdiagnose signals, or other indicators)?
Are there any known constraints with Assets.xcassets usage for Live Activities that could cause bundled assets not to render even when present?
We can provide
A minimal reproduction Xcode project (preferred)
The IPA build
Build logs (Xcode/EAS)
Screenshots/video and a sysdiagnose captured after reproduction
Thank you for your guidance.
Best regards
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Some of the users of my app reported that, the widgets cannot be loaded, event after restarts and re-installs. It seems that it is not rare, I have tens of reports on this (and probably much more who didn't report).
It seems the widget is blank even on the gallery screen while you are first adding it:
struct SingleWidgetProvider: AppIntentTimelineProvider {
@Environment(\.widgetFamily) var family
private let viewModel: WidgetViewModel = WidgetViewModel()
func placeholder(in context: Context) -> SingleEntry {
SingleEntry(date: Date(), habit: .singleSample)
}
func snapshot(for configuration: SingleWidgetConfigurationIntent, in context: Context) async -> SingleEntry {
guard let habit = Array(PersistenceManager.shared.retrieveHabitList().habits).first else {
return SingleEntry(date: Date(), habit: .singleSample)
}
let displayable = viewModel.displayableFromHabit(habit, separateComponents: true, secondOffset: 0)
return SingleEntry(date: Date(), habit: displayable)
}
func timeline(for configuration: SingleWidgetConfigurationIntent, in context: Context) async -> Timeline<SingleEntry> {
var entries: [SingleEntry] = []
guard let counter = configuration.currentCounter else {
return Timeline(entries: [SingleEntry(date: Date(), habit: .singleSample)], policy: .atEnd)
}
guard let habit = PersistenceManager.shared.retrieveHabit(habitKey: counter.id) else {
return Timeline(entries: [SingleEntry(date: Date(), habit: .singleSample)], policy: .atEnd)
}
let currentDate = Date()
for secondOffset in 0 ..< 100 {
let displayable = viewModel.displayableFromHabit(
habit,
separateComponents: true,
secondOffset: secondOffset,
symbolName: habit.habitSymbol?.name ?? "",
overrideColor: configuration.currentColor.color,
overrideButtonVisibility: configuration.currentButtonVisibility,
overrideDisplayOption: configuration.currentDisplayOption
)
let entryDate = Calendar.current.date(byAdding: .second,
value: secondOffset,
to: currentDate)!
let entry = SingleEntry(date: entryDate, habit: displayable)
entries.append(entry)
}
return Timeline(entries: entries, policy: .atEnd)
}
}
struct SingleEntry: TimelineEntry {
let date: Date
let habit: HabitDisplayable
}
static var singleSample: HabitDisplayable {
return HabitDisplayable(habitKey: nil,
title: LS("sampleWidgetHabitTitle"),
dates: [Date(timeIntervalSince1970: 1507158360)],
displayOption: .dayMonthYear,
secondOffset: 0,
separateComponents: true)
}
func displayableFromHabit(
_ habit: Habit,
separateComponents: Bool,
secondOffset: Int,
symbolName: String = "",
overrideColor: Color? = nil,
overrideButtonVisibility: WidgetButtonVisibility? = nil,
overrideDisplayOption: WidgetDisplayOption? = nil
) -> HabitDisplayable {
let latestDates: [HabitDate]
let displayOption: DisplayOption
if let overrideDisplayOption {
if overrideDisplayOption == .sameAsCounter {
displayOption = habit.settings?.toValue.displayOption ?? .dayMonthYear
} else {
displayOption = DisplayOption(rawValue: overrideDisplayOption.rawValue - 1) ?? .dayMonthYear
}
} else {
displayOption = habit.settings?.toValue.displayOption ?? .dayMonthYear
}
let displayMode = displayOption.mode
switch displayMode {
case .timePassed, .date:
latestDates = PersistenceManager.shared.latestDate(habit: habit).map { [$0] } ?? []
case .activity:
latestDates = PersistenceManager.shared.retrieveHabitDates(habit: habit, limitDate: displayOption.limitDate())
}
let displayButton: Bool
if let overrideButtonVisibility {
if overrideButtonVisibility == .sameAsCounter {
displayButton = habit.settings?.toValue.buttonType == .onRow
} else {
displayButton = overrideButtonVisibility == .show
}
} else {
displayButton = false
}
return HabitDisplayable(
habitKey: habit.habitKey,
title: habit.title,
dates: latestDates.map { $0.date },
displayOption: displayOption,
secondOffset: secondOffset,
separateComponents: separateComponents,
color: overrideColor ?? habit.habitColor?.color ?? .appPrimary,
symbolName: symbolName,
displayButton: displayButton
)
}
I provided a large portion of my code, let me know if you need more. The strange thing here is, even if the DB connection is broken somehow, it should have shown the default option (singleSample).
I am not able to reproduce/fix this for months now, so any help is very appreciated.
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Hi there,
I'm adding a new widget using the new WidgetConfigurationIntent which takes a number of parameters, including one which conforms to AppEntity. It is defined as an optional.
When the user is configuring the widget, after one of the suggested entities is chosen, there is no way to return to a state where this value is nil. Is this possible? I'd like the user to be able to select "None" for this parameter. For now, I'm using a bool to determine whether the AppEntity parameter is used.
Thanks!
I noticed that with iOS 18, when adding a widget to the Control Center, there is now some "grouping system". I'm interested in the Capture group, which contains native widgets from Apple as well as third party apps like Instagram and Blackmagic cam, widgets in this group open the camera. My widget also opens the camera in my app, how can I add it to this group?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
SwiftUI
WidgetKit
App Intents
Live Activity Start Token not generating after certain days of usage. We have implemented Live Activity feature where the initial activity is launched by our backend. But to start that first live activity I need push to start token which is generating for few days but all of sudden after certain days it stops generating. Currently we are in development phase so we test it on multiple devices and multiple time we are doing install and uninstall.
STEPS TO REPRODUCE
Install the app
Start token gets generated which is sent to our server
After certain duration server sends the first live activity using that token
user opens the app then we receive the updated token and send that token to server
server uses that updated token to further update the live activity.
All this works fine. But after a week of usage we are observing that we stop getting start token from APNS. Not sure where exactly the thing is breaking. We have tried with different devices and different bundle identifiers but behaviour is same for all.
func generateStartToken() {
Task.detached { [weak self] in
guard let self else { return }
await self.observeActivityPushTokenAndState()
for await data in ActivityKit.Activity<LiveActivityAttribute>.pushToStartTokenUpdates {
let token = data.map { String(format: "%02x", $0) }.joined()
print("Activity Start token: ", token)
}
}
}
func observeActivityPushTokenAndState() {
Task.detached {
for await activity in ActivityKit.Activity<LiveActivityAttribute>.activityUpdates {
Task {
for await tokenData in activity.pushTokenUpdates {
let updatedToken = tokenData.map { String(format: "%02x", $0) }.joined()
print("Activity Update token: ", updatedToken)
}
}
Task {
for await content in activity.contentUpdates {
let updatedContent = content.state
print("Activity Updated: ", updatedContent)
}
}
}
}
}
I have a question about how a watch widget can access HealthKit data. Does it, as the large model mentioned, share data through an App Group, or does it directly access the HealthStore?
Hi, I have a class project I am working on (with a due date tomorrow, unfortunately RIP to me). But I have made my project about adding accessibility to a Unity game. I've successfully added apple unity core and accessibility plugins to my project, and my project builds. But I have simple text nodes and buttons and they aren't accessible with voiceover once I build/export my game and test. I am only building for MacOS right now (for the assignment).
I don't have too much experience with Unity, but I am relatively experienced with accessibility (even formerly an intern and contractor at Apple for accessibility). So I wonder if I am just using Unity incorrectly? Perhaps I've done something to my build process (or haven't done something I should)? I've attached a photo of what my dev environment looks like in Unity, I've focused a text node (on the left) and on the right are my AccessibilityNode settings.
Any help would be awesome, even if I don't make my deadline tomorrow... :*(
Project repo is here, if it is helpful: https://github.com/frankelavsky/PGD_final_project
Thanks!
I am seeing a really weird behavior with Live Activities. The Live Activity is always appearing on the simulator. However the Live Activity is only appearing on my physical device when there is no other widget in the widget bundle shown below.
@main
struct HoerspielWidgetsBundle: WidgetBundle {
var body: some Widget {
// Uncomment the line below and the Live Activity will no longer appear
// UpNextWidget()
PlaybackLiveActivity()
}
}
Annotating that var with @WidgetBundle has no effect.
There are no logs indicating an error, the function to request a Live Activity does not throw and the status of the activity is active.
Both the widget and the Live Activity are working fine otherwise. NSSupportsLiveActivities is set to true in the correct Info.plist file. I am not running any beta software and the physical iPhone is on the newest version (iOS 18.5). Using the template when adding a new target in Xcode, I was able to set up a similar app where the Live Activity works as expected.
I am really at a loss here which additional information I should provide or how this issue can be resolved.
Thank you for your help.
Hello forum,
I want to keep my app running in the background after user swaps up, for the purpose of workout tracking.
start up the task and continuously receipt GPS updates
process the location data
show the data on a live activity
Two examples
Strava
paddlelogger
Question:
Does this mean, these two apps would just pause when the .backgroundTimeRemaining becomes 0?
How does a workout app "work" in background mode, do I need to handle budget running out?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
Core Location
Maps and Location
Background Tasks
Hi, I’m using SwiftData with an @Observable DatabaseManager class that is shared between my app and a widget. This class is located inside a Swift package and looks roughly like this:
public final class DatabaseManager {
public static let shared = DatabaseManager()
private init() {
let groupID = "group.com.yourcompany.myApp"
let config = ModelConfiguration(groupContainer: .identifier(groupID))
let c = try! ModelContainer(for: MyModel.self, configurations: config)
self.container = c
self.modelContext = c.mainContext
}
public private(set) var container: ModelContainer
public private(set) var modelContext: ModelContext
}
In the main app, I inject the container and context like this:
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.modelContainer(DatabaseManager.shared.container)
.modelContext(DatabaseManager.shared.modelContext)
}
}
}
Both the widget and the main app import the same package, and both use DatabaseManager.shared for reading and writing objects.
The problem:
When the widget updates an object using an AppIntent, the change is not reflected in the main app unless I fully terminate and relaunch it. If I just bring the app back to the foreground, it still shows stale data.
Is there a recommended way to make the main app observe or reload SwiftData changes that were made in the widget (via the same shared app group and container)? I’m already using .modelContainer(...) and .modelContext(...) in the app, and everything else works fine — it’s just the syncing that doesn’t happen unless I force-relaunch the app.
Thanks!
Hello,
I am trying to create a Home Screen widget for iOS that displays device usage statistics — similar to the built-in Screen Time widget Apple provides. The goal is to show the average device usage for a specified period (daily, weekly, or monthly) and optionally include a comparison with the previous period.
I noticed that Apple’s own Screen Time widget presents such information. However, after reviewing the public documentation, I could not find any available API that allows a developer to create a similar experience.
To explore possible alternatives, I implemented a SwiftUI view inside a com.apple.deviceactivityui.report-extension using the Family Controls and Device Activity frameworks. The view works fine within the main app and the report extension context, but when I attempted to use the same view in a WidgetKit extension, I received an error at runtime. This suggests that views from com.apple.deviceactivityui.report-extension are not usable inside widgets, which I understand may be due to sandboxing or limitations of how the extension points are designed.
So far, I’ve found no way to access cumulative or average usage data (screen time, app usage, etc.) from system APIs that can be shown in a widget context. My understanding is that Family Controls and Device Activity frameworks allow observing ongoing activity and building usage reports inside the app, but do not provide access to the same historical or summarized data that Apple’s own widgets display.
Could you please confirm:
Whether there is any supported way to access average device usage (screen time) data for use in a widget?
If not, is this an intentional limitation due to privacy concerns, or is there a roadmap for exposing such APIs in the future?
Are there any APIs or entitlements that could allow similar functionality via WidgetKit?
Thank you for your time and support.
Best regards,
I am currently developing an interactive widget, but an AppIntent issue blocked me for 2 days.
I have an AppIntent named TimerActionIntent, which has two parameters: TimerType and TimerAction. Here is the code:
import AppIntents
enum TimerType: Int, CaseIterable, AppEnum, AppEntity {
case sleep
case feeding
static let typeDisplayRepresentation: TypeDisplayRepresentation = "Timer Type"
static let caseDisplayRepresentations: [TimerType : DisplayRepresentation] = [
.sleep: "Sleep",
.feeding: "Feeding"
]
}
enum TimerAction: Int, CaseIterable, AppEnum, AppEntity {
case start
case pause
case stop
static let typeDisplayRepresentation: TypeDisplayRepresentation = "Timer Action"
static let caseDisplayRepresentations: [TimerAction : DisplayRepresentation] = [
.start: "Start",
.pause: "Pause",
.stop: "Stop"
]
}
struct TimerActionIntent: AppIntent {
static let title: LocalizedStringResource = "Operate a Log Timer"
@Parameter(title: "Timer", default: .sleep)
var timerType: TimerType
@Parameter(title: "Action", default: .start)
var action: TimerAction
static var isDiscoverable: Bool = false
static var openAppWhenRun: Bool = false
init() {}
init(timerType: TimerType, action: TimerAction) {
self.timerType = timerType
self.action = action
}
func perform() async throws -> some IntentResult {
// perform the action
Self.openAppWhenRun = state == .stopped
}
return .result()
}
}
I can't execute the AppIntent if using the following code:
Button(intent: TimerActionIntent(timerType: .sleep, action: .start)) {
// button view
}
// or
let intent = TimerActionIntent()
intent.timerType = timerType
intent.action = .start
Button(intent: intent) {
// button view
}
and only execute when initialize TimerActionIntent without any parameters and @Parameter has the default value. e.g.
Button(intent: TimerActionIntent()) {
// button view
}
I have some logs in the Console app:
default 17:51:27.626382+0800 linkd Accepting XPC connection from PID 39255 for service "com.apple.linkd.registry"
default 17:51:27.637511+0800 WidgetsExtension Beginning PerformAction <<SB:788D850BBBC5>>
default 17:51:27.637540+0800 WidgetsExtension Beginning InitializeAction <<SB:ACBC7A27CCBF>>
default 17:51:27.637556+0800 WidgetsExtension [InitializeAction <<N:ACBC7A27CCBF>>] Found TimerActionIntent matching TimerActionIntent registered with AppManager
default 17:51:27.637725+0800 WidgetsExtension Prepared timerType to TimerType(TimerType/0))
default 17:51:27.637744+0800 WidgetsExtension Prepared action to TimerAction(TimerAction/0))
default 17:51:27.637772+0800 WidgetsExtension Ending InitializeAction <<SE:ACBC7A27CCBF>>
default 17:51:27.637795+0800 WidgetsExtension Beginning ResolveParameters <<SB:6C7CA02308AD>>
default 17:51:27.639807+0800 WidgetsExtension Building resolver for parameter timerType<TimerType> = TimerType/0
default 17:51:27.640160+0800 WidgetsExtension Building resolver: EntityIdentifier → TimerType:TimerActionIntent:timerType
default 17:51:27.640202+0800 WidgetsExtension Ending ResolveParameters <<SE:6C7CA02308AD>>
default 17:51:27.640221+0800 WidgetsExtension Beginning NeedsDisambiguation <<SB:8E482F9CCCB0>>
default 17:51:27.641328+0800 WidgetsExtension Ending NeedsDisambiguation <<SE:8E482F9CCCB0>>
default 17:51:27.641344+0800 WidgetsExtension Ending PerformAction <<SE:788D850BBBC5>>
error 17:51:27.642316+0800 chronod Perform action connection operation completed with error: Error Domain=LNActionExecutorErrorDomain Code=2010 "(null)"
error 17:51:27.642774+0800 chronod Operation `<LNPerformActionConnectionOperation: 0x600002c4a180, identifier: F8FB77C5-7F8A-4670-BB8C-465DE4EAB6B8>` error Error Domain=LNActionExecutorErrorDomain Code=2010 "(null)"
default 17:51:27.643358+0800 linkd Invalidated XPC connection from PID 39255 for service "com.apple.linkd.registry"
I can't find any details about the error " Error Domain=LNActionExecutorErrorDomain Code=2010 "(null)""
The environment:
Xcode: 16.4/26 beta 5
iOS: iOS Simulator 18.5, iOS Simulator 26, iPhone 16 Pro Max 18.6
macOS 15.6
Can anyone help me, please!
Topic:
App & System Services
SubTopic:
Widgets & Live Activities