Dear Developer Technical Support,
I wanted to ask for technical advice regarding the DeviceActivityMonitor which is part of the DeviceActivity framework:
The DeviceActivityMonitor has a very strict memory limit of 6MB. That’s not a lot and it doesn't leave a lot of room for any kind of code that accesses permanently stored data.
I would therefore like to ask for advice on best-practices on how to share information between the main app and that extension:
- Is
UserDefaultsa good idea to use here? - Can/should we use
CoreDataorSwiftData? - Should we build super small file-based data sharing (e.g. via
.plists)?
Why is it necessary to share data? This can be simple things that inform the decision of the device activity monitor in intervalDidStart, intervalDidEnd, eventDidReachThreshold, eventWillReachThresholdWarning. For example a setting where the user decides if they want to receive a push notification on eventWillReachThresholdWarning. Or the list of tokens that is supposed to be blocked in eventDidReachThreshold or intervalDidStart.
I’m asking because even though we are super careful and conservative about memory allocations in our DeviceActivityMonitor we are regularly seeing it being killed due to memory pressure.
What’s the best way to approach this? I’m grateful for any kinds of hints!
Thanks a lot and have a great day!
– Frederik