Detecting Termination and Re-establishing Connection with DeviceActivityReport App Extension

Hello,

I have an iOS app using the DeviceActivityReport app extension. Occasionally, the extension gets terminated (likely due to reaching memory limit**), which in turn disrupts the connection with the main app.

How can the main app detect when the DeviceActivityReport extension has been terminated due to memory constraints, and what's the best way to re-establish the connection afterward?

Thanks in advance for your insights and suggestions!

** I'm also unsure why the extension should be reaching its memory limit. When profiling the extension in XCode, it never reaches above 15MB, and I know the limit is 100MB. It's not doing anything out of the ordinary - and I've seen very similar complaints about DeviceActivityReport terminating on these forums. Any thoughts on how to prevent termination in the first place would also be super helpful!

Replies

Hey ! We encounter similar issues in the past, and didn't find any proper documented way to monitor the DeviceActivityReport extension state, or to prevent crashes from happening. You can provide a way for your user to reload the view himself in case of crash using regular SwiftUI methods.

We've opened several radars, some of them more than a year ago, without any answer at the moment. I would suggest you to do the same, the more they are, the more likely they'll fix it !

Regards !

  • Thanks for the reply! Already have reload capabilities in my app but it's still a terrible user experience for the report to show up blank so often. Seems like other screen time apps have been able to mitigate this issue mostly, but not sure what their workarounds are. I'm thinking of creating a group chat for iOS screen time devs to troubleshoot together since the APIs are still pretty buggy and it's hard to get answers from Apple. If you're interested, email me at screentimedev23 @ gmail.com

Add a Comment

I've encountered the same issue, but based on my testing, it's not because of the 100MB limit. It's actually because iOS, when it's running low on resources, prioritizes cleaning up processes with lower priority. DeviceActivityReport falls into that category. You can try playing games or watching videos, and it's almost a guaranteed way to reproduce the issue. However, successfully reloading it is indeed quite challenging. I wonder how other apps handle this?

  • I've been able to manually refresh the report UI by incrementing an id:

    @State var reportId = 0 ... DeviceActivityReport(context, filter: filter) .id(reportId) Button(action: { reportId += 1 }) { Text("Refresh") }

    However, what I really want to do is detect from the host app when the app extension or DeviceActivityReportService gets terminated, and then programmatically refresh the view. Has anyone been able to figure out how to detect termination of the extension?

Add a Comment

How do you know about that limit? Is it documented anywhere?