I think I have found a bug in the Apple "Screen Time" API.
I have filed it via a Feedback Assistant, but I can see that some apps have somehow found a workaround to this issue — so wondering how they did it.
The issue:
Create a simple two tabs view:
TabView {
Tab1View()
.tabItem {
Label("Tab 1", systemImage: "1.circle.fill")
}
Tab2View()
.tabItem {
Label("Tab 2", systemImage: "2.circle.fill")
}
}
Each tab has a different "Screen Time" report, e.g.
struct Tab2View: View {
var body: some View {
DeviceActivityReport(Utils.weeklyContext, filter: Utils.filterWeekly)
}
}
When you switch the tabs quickly, the "Screen Time" process crashes, leaving both reports blank.
The size of the "DeviceReportActivity" remains the same (it's just blank), so there is no way to tell if it crashed. Also, there is no way to know that the "Screen Time" process has crashed. This leaves the app in an unusable state.
Here is a video illustrating the issue:
https://www.youtube.com/watch?v=WrRpohf9tmw&ab_channel=MarcinCzech
The code is here:
https://github.com/AndroidGecko/Screen-Time/tree/screen_time_issues
However, apps like https://jomo.so/ or https://www.opal.so/ have tabs with two "Screen Time" reports.
And if you switch tabs quickly, you can see it breaking, but somehow they make it re-appear. I know I can re-fresh the view using .id()
on the report, but I cannot see a way of detecting when the report crashes. Forcing a new .id
on each tab switch is not the right solution as it re-fetches the whole report (Jomo and Opal don't do it).
Question:
How can I detect that a "Screen Time" process has crashed? (to create a workaround for that issue). Or maybe there is another way to approach this issue?
Thank you 🙏