Search results for

DeviceActivityMonitor

127 results found

Post

Replies

Boosts

Views

Activity

DeviceActivityMonitorExtension functions not being called
I'm having trouble with my DeviceActivityMonitorExtension. The intervalDidStart function is not being called when the scheduler is created. Does anyone have an idea why this is? let schedule = DeviceActivitySchedule( intervalStart: DateComponents(hour: 15, minute: 23), intervalEnd: DateComponents(hour: 16, minute: 55), repeats: true ) class MySchedule { static public func setSchedule() { let center = DeviceActivityCenter() center.stopMonitoring([.daily]) do { try center.startMonitoring(.daily, during: schedule) } catch { print(Error monitoring schedule: , error) } } } class DeviceActivityMonitorExtension: DeviceActivityMonitor { override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) SelectedApps.shared.setRestrictions() } private let _SelectedApps = SelectedApps() class SelectedApps: ObservableObject{ @Published var selection: FamilyActivitySelection let store = ManagedSettingsStore() init() { if let savedSelection = UserDefaults.standard.object(forKe
3
0
1.1k
Jul ’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
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
Apr ’23
DeviceActivityMonitor eventDidReachThreshold triggering every time in same second as intervalDidStart gets called
Hello, I am trying to make use of Screentime API in my app, I have issue with the DeviceActivityMonitor extension. I have schedule DeviceActivitySchedule which I set like this: let schedule = DeviceActivitySchedule( intervalStart: DateComponents(hour: 00, minute: 00), intervalEnd: DateComponents(hour: 23, minute: 59), repeats: false ) and DeviceActivityEvent which I set like this: let dateComponent = DateComponents(minute: 1) var events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [ .encouraged: DeviceActivityEvent(threshold: dateComponent) ] The issue is that every time I start monitoring, by calling this piece of code from the app: do { print(Try start monitoring...) try center.startMonitoring(.daily, during: schedule, events: events) } catch { print(Error: , error) } I catch in the extension that the event intervalDidStart is called, but in the same second I get called eventDidReachThreshold. What could be done wrong? Is event set properly? I was trying to set event with different Datecompon
3
0
1.7k
Apr ’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
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 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
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
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
Monitor DeviceActivityEvent for all categories: ActivityCategoryPolicy.all? Without using FamilyActivityPicker
Using ManagedSettings I'm able to shield all categories of applications using ActivityCategoryPolicy.all , without the user using picking categories with the FamilyActivityPicker. I would like to create a DeviceActivityMonitor which monitors events for all (or a specific) categories of apps, without the user needing to interact with the FamilyActivityPicker. Is this possible? And an extra question: is there no way to pick a specific category to shield? Just like we are able to do with ActivityCategoryPolicy.all, instead something like: ActivityCategoryPolicy.games
0
0
1.1k
Feb ’23