Search results for

DeviceActivityMonitor

127 results found

Post

Replies

Boosts

Views

Activity

Memory limit for Device Activity Monitor Extension
I am trying to develop an application that can enforce Screen Time restrictions on the target device, however I get stuck at the part where I have scheduled callbacks for my class that implements the extension for DeviceActivityMonitor. For debugging, I first attach to the app extension target process via Debug > Attach to Process > Process Name. But after scheduling monitoring that receives a callback immediately, the process exits with the following error: Thread 1: EXC_RESOURCE (RESOURCE_TYPE_MEMORY: high watermark memory limit exceeded) (limit=6 MB) Is the maximum allowed memory for Device Activity Monitor extensions really just 6 MB, or am I doing something wrong? If it is indeed the case, is there any way to increase it? 6 MB seems quite restrictive to me.
1
0
1.9k
Aug ’23
Setting values in UserDefaults in DeviceActivityMonitor extension
I understand that the DeviceActivityMonitor extension is designed to be very lightweight, and the system terminates the extension as soon as its callback functions return. However, I want to save values to UserDefaults inside the extension's callback functions. This creates concurrency issues for my app because the documentation for UserDefaults states that When you set a default value, it’s changed synchronously within your process, and asynchronously to persistent storage and other processes. In order to guarantee that these values are persisted before the extension terminates my app, I want to call UserDefaults.synchronize(), but its documentations states that it's unnecessary and shouldn't be used. Furthermore, it's listed under Legacy but not marked deprecated. Is synchronize() the recommended way to solve my concurrency problem? Or could there be a better way to wait for storage synchronization before returning from a synchronous function?
5
0
2.1k
Jun ’23
ManagedSettings can't shield Messages and other system apps
When using ManagedSettingsStore to shield apps, no system apps are shielded even when specifying all application categories. Here is my code: managedSettings.shield.applicationCategories = .all() Even when using the FamilyActivityPicker and selecting All Apps & Categories system apps like Messages do not get shielded. managedSettings.shield.applicationCategories = .specific(selectedCategories) I find this strange, since Messages exists inside the Social category, and is tracked fine using DeviceActivityMonitor. Why can't it be shielded using app categories? I'd like to be able to shield all apps, including Messages, without having the user to specifically select the apps using FamilyActivityPicker. Is that possible?
1
0
1.4k
May ’23
Reply to Trigger Action After eventDidReachThreshold
Yes, you can create a DeviceActivityMonitor app extension and override its eventDidReachThreshold function. The system will invoke your principal class's implementation of that function whenever an event's threshold is reached. You can create one of these extensions in Xcode by clicking File > New > Target > Device Activity Monitor Extension. Xcode will autogenerate a properly configured extension target with a simple implementation of DeviceActivityMonitor that you can then modify to shield apps whenever a threshold is reached.
Topic: App & System Services SubTopic: General Tags:
Apr ’23
Trigger Action After eventDidReachThreshold
I am trying to configure my app to monitor device screen time and shield apps after a certain amount of screen time is reached. Here's the scheduled I created: let schedule = DeviceActivitySchedule( // I've set my schedule to start and end at midnight intervalStart: DateComponents(hour: 0, minute: 0), intervalEnd: DateComponents(hour: 23, minute: 59), // I've also set the schedule to repeat repeats: true ) class MySchedule { var item: NoteItem init(item: NoteItem) { self.item = item } public func setSchedule() { print(Setting schedule...) print(Hour is: , Calendar.current.dateComponents([.hour, .minute], from: Date()).hour!) var threshold = DateComponents(hour: item.hour, minute: item.min) let events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [ .discouraged: DeviceActivityEvent( applications: NotificationsModel.shared.selectionToDiscourage.applicationTokens, threshold: threshold ) ] let center = DeviceActivityCenter() do { print(Try to start monitoring...) try center.startMonitoring(.daily, during: sc
1
0
972
Apr ’23
Reply to Setting values in UserDefaults in DeviceActivityMonitor extension
I'm storing timestamps of certain screen time thresholds with DeviceActivityMonitor. Whether or not this is its intended use, something is still off. DeviceActivityMonitor is part of an app extension that is invoked and terminated by the system. Once its functions return, the extension is immediately terminated, meaning there may be data in UserDefaults that never gets persisted. The also docs don't say it's a no-op just that it's unnecessary - but maybe it's necessary inside an app extension?
Topic: App & System Services SubTopic: General Tags:
Apr ’23
DeviceActivity App Extension Lifecycle
I've asked several questions about DeviceActivity performance issues where the answers have cited limitations to the lifecycle of the DeviceActivity App Extensions. For example: Question about DeviceActivityReport lag and performance issues responded letting me know that my extension may be exceeding its memory limit of 100MB and subsequently getting terminated by the system. Question about async tasks in DeviceActivityMonitor responded letting me know that the monitor extensions lifecycle ends and is terminated by the system once all synchronous functions return, so it has no async support. I couldn't find either of these facts documented anywhere, and the DeviceActivity docs mention very little about how the extensions actually work. In general, it seems like these app extensions are basically a black box. Is there any additional comprehensive documentation about the true lifecycle of the app extensions, their limitations, and how apps should handle error cases (like the system terminating the app
1
0
978
Mar ’23
Reply to Can we send Local Push Notifications from DeviceActivityMonitor extension?
Do you have an example of using App Group to share data? My DeviceActivityMonitor extension is firing the intervalDidStart(), but the categoryTokens in stored in the shared model are empty when it fires. However, when I run it using a button action in the foreground, the categoryTokens are founded and successfully shielded. I tried adding App Group capability to the main app target, and the DeviceActivityMonitorExtension target. Any insight would be appreciated.
Mar ’23
Can we send Local Push Notifications from DeviceActivityMonitor extension?
I'm wondering if we able to send Local Push Notifications from DeviceActivityMonitor extension... If we have to use AppGroups to pass info between an app and the extension, could we post notification though UNNotificationRequest? I also tried to push data through NotificationCenter, also doesn’t work. Can we do so, or did something wrong? Should these cases that I described above work from iOS 16 and above or not? Thank you!
2
0
1.3k
Mar ’23
Interact with ManagedSettingsStore from DeviceActivityMonitor
I want to remove shield restrictions for apps. Following the WWDC21 video, I declare ManagedSettingsStore and trying to reset restrictions: class MyDeviceActivityMonitor: DeviceActivityMonitor { let store = ManagedSettingsStore() public override func intervalDidEnd(for activity: DeviceActivityName) { super.intervalDidEnd(for: activity) store.shield.applications = nil } } Will this string has impact on the app store.shield.applications = nil? Because now, while testing it seems that I'm dealing with two different stores. Or again it is doesn’t synced by default and let store = ManagedSettingsStore() will create store which will be different than store on which the app is relays on? Thank you!
2
0
2.0k
Mar ’23
Reply to Interact with ManagedSettingsStore from DeviceActivityMonitor
Starting in iOS 16, ManagedSettingsStores will share the same settings in the DeviceActivityMonitor extension as the host application. Meaning if you set a setting (like shield.applications) in ManagedSettingsStore() in the app, you will see the same setting in ManagedSettingsStore() in the extension. So, for example this will shield apps in the host application, and clear those same shields once the activity ends. App: func shieldApplications() { let selections = FamilyActivitySelection(includeEntireCategory: true) /* Get Application Tokens from FamilyActivityPicker */ let store = ManagedSettingsStore() store.shield.applications = selections.applicationTokens } Extension: class MyDeviceActivityMonitor: DeviceActivityMonitor { let store = ManagedSettingsStore() public override func intervalDidEnd(for activity: DeviceActivityName) { super.intervalDidEnd(for: activity) store.shield.applications = nil } } If you do not want this behavior, please use the ManagedSettingsStore(named:) initializer
Topic: App & System Services SubTopic: General Tags:
Mar ’23
DeviceActivityMonitor can't detect private browsing
It seems like private browsing is undetectable with DeviceActivityMonitor for two reasons: Specific web domains do not cause the monitoring threshold callback functions to fire, due to the privacy setting Safari is not able to be monitored as an app or a category. It doesn't appear in the FamilyActivityPicker, and it doesn't appear to belong to any Screen Time category when viewing Safari's information in Screen Time Settings Is there any way to monitor device activity during private browsing? If not, that seems like a big problem for apps that allow parents to set device activity limits for their kids.
1
0
773
Mar ’23
DeviceActivityCenter stops monitoring if another Screen Time app starts monitoring during the same schedule
I've downloaded another screen time app that uses DeviceActivityMonitor, and once that app starts monitoring during an active monitoring schedule on my app - my app's monitoring schedule immediately ends. Is this expected behavior? Can't find this in any of the docs, but are two separate apps allowed to monitor activities during an overlapping schedule?
1
0
854
Feb ’23
How to trigger intervalDidStart in DeviceActivity API?
I have followed the two videos about Screen time API in wwdc 21 and 22. Now i want to sheild some apps during sleeping, but I encounter some problems. Problem I faced I write my monitor and override intervalDidStart and intervalDidEnd . Here is a simplified version class Mymonitor: DeviceActivityMonitor { let store = ManagedSettingsStore() override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) store.shield.applications = selection.applicationToken } then I use deviceActivityCenter to start monitor func StartSleep (_ startTime : DateComponents) { let schedule = DeviceActivitySchedule(intervalStart: startTime, intervalEnd: DateComponents(hour: 4, minute: 0), repeats: true ) let center = DeviceActivityCenter() center.stopMonitoring([.daily]) try! center.startMonitoring(.daily, during: schedule) } However, when I use StartSleep. The applications is not shielded. I have noticed that I haven't use Mymonitor in any place. In the demo Code, it seems i just ne
2
0
1.2k
Feb ’23