Hi! DeviceActivityMonitors methods IntervalDidStart, IntervalDidEnd and eventDidReachThreshhold do not seem to be called on my application. Has anyone found a solution to this problem. Thank you in advance.
Search results for
DeviceActivityMonitor
127 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Is there a way to use DeviceActivityMonitor to monitor a user's Screen Time ONLY on the current device, even if they have Share Across Devices enabled in their Screen Time settings? For DeviceActivityReport, you can provide a DeviceActivityFilter which can specify the devices you want to show. But I have not seen any way to filter devices with the DeviveActivityMonitor API. I would expect there to be a additional argument to DeviceActivityEvent's init method: init( applications: Set = [], categories: Set = [], webDomains: Set = [], threshold: DateComponents ) Where you can specify devices as well. Right now, it seems like the default behavior is to monitor across all shared devices, which is causing problems for my application.
Topic:
App & System Services
SubTopic:
General
Tags:
Managed Settings
Family Controls
Device Activity
Screen Time
My app uses DeviceActivitySchedule to let users set schedules to block certain apps. I naturally want to understand how my users are using the feature, so I capture analytics events using Segment. Ever since the release of iOS 17.1, analytics events from DeviceActivityMonitor have stopped firing. I believe this is due to the fact that the app extension that DeviceActivityMonitor runs in does not support asynchronous network requests. (However, I'm not sure why the analytics were working correctly with iOS 16). What is the best way to capture analytics inside the DeviceActivityMonitor app extension in iOS 17?
Topic:
App & System Services
SubTopic:
General
Tags:
Extensions
Managed Settings
Family Controls
Device Activity
Hey, I’m having some issues with DeviceActivitySchedule and DeviceActivityMonitor. I want to create a schedule that blocks apps (by family control) when it starts. However, even when the schedule is supposed to start on this iPhone, nothing happens, and no logs are being recorded main target: // TestView_.swift // Sloth // // Created by on 11/01/2025. // import SwiftUI import DeviceActivity import FamilyControls import ManagedSettings struct TestView_: View { var body: some View { VStack(spacing: 20) { Text(Test DeviceActivityMonitor) .font(.title) Button(Start test mon) { let now = Date() let start = Calendar.current.date(byAdding: .minute, value: 2, to: now)! let end = Calendar.current.date(byAdding: .minute, value: 20, to: now)! print(thd) DeviceScheduleTester().scheduleTestActivity(startDate: start, endDate: end) } } .padding() } } extension DeviceActivityName { static let daily = DeviceActivityName(daily) } DeviceActivityMonitor: class DeviceScheduleTester { private let center
I started monitoring using the following code: deviceActivityCenter.startMonitoring( DeviceActivityName(name), during: makeDailySchedule(), events: events ) Where: DeviceActivitySchedule( intervalStart: DateComponents(hour: 0, minute: 0), intervalEnd: DateComponents(hour: 23, minute: 59), repeats: true, warningTime: nil ) In DeviceActivityMonitor, I read and write data using UserDefaults and keep the logic minimal to ensure the size does not exceed 6MB. However, after a period of time, monitoring continues to fail. Why is this happening? How can I resolve this issue?
My app monitors DeviceActivityEvents with no categories, apps, or websites selected because we want to monitor their time spent on all categories, apps, and websites. This is because my app gives users rewards for keeping their total Screen Time low. Unfortunately, it has been seemingly impossible to align the Screen Time shown with DeviceActivityReport to the Screen Time monitored with DeviceActivityMonitor. By default, the DeviceActivityReport captures more Screen Time than the DeviceActivityMonitor by default. But if I try to filter the report by totalActivityDuration on each category, it misses some Screen Time captured by the monitor (like FaceTime, for instance). I simply want to report to the user exactly the Screen Time I am monitoring by default with DeviceActivityMonitor. Is that possible without selecting any categories, apps, or websites in the monitor?
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!
Topic:
App & System Services
SubTopic:
General
Tags:
Managed Settings
Family Controls
Device Activity
Screen Time
Hi everyone, I am a beginner in Swift and I am currently using DeviceActivityMonitor to develop an app for parents to control their children's app usage time. During the development process, I found that the DeviceActivityMonitor has a 6MB memory limit in the background, and my app exceeds this limit after running for a long time. I would like to know how to reduce the memory usage of DeviceActivityMonitor in the background, or where I can check the memory usage of DeviceActivityMonitor and see which variables are consuming memory. Additionally, I want to know if a new instance of the DeviceActivityMonitor class is created every time it is called? Thank you for your help!
I'm following the video with explanation of how to dealing with DeviceActivityMonitor extension. I'm facing the issue with empty ManagedSettingsStore when I'm trying to retrieve discouraged apps. The apps successfully where blocked on the selection step via .familyActivityPicker. The problem is that I can’t retrieve discouraged apps. I read that Model.shared won’t work in extension. To sync an app and extension we need to use AppGroups. Do we need to use AppGroups if we follow code like in the video?
Topic:
App & System Services
SubTopic:
General
Tags:
Managed Settings
Family Controls
Device Activity
Screen Time
There is a way to allow DeviceActivityMonitor to make UI changes? Currently I have some code in the intervalDidStart and intervalDidEnd that updates Core Data entities, and it works correctly. However, the changes are only reflected if the app is terminated and opened again. Thus, if the app is opened and one of the methods inside the DeviceActivityMonitor is being called, the UI won't be updated. PS: I am using @FetchRequest to retrieve the core data entities called BlockEntity, and I have a little circle in the UI which should indicate the status of the block: active/inactive, so it would be nice to update the color in real time when intervalDidStart or intervalDidEnd are called.
Topic:
App & System Services
SubTopic:
General
Tags:
Family Controls
Device Activity
Managed Settings
Screen Time
I am using the DeviceActivityMonitor eventDidReachThreshold functionality, but it became very unreliable on the iOS 17.5 beta. Anyone experiencing similar problems? Any known workarounds?
Topic:
App & System Services
SubTopic:
General
Tags:
Family Controls
Device Activity
Managed Settings
Screen Time
I am having a lot of trouble reliably making network requests from the DeviceActivityMonitor extension. In the app extension, when intervalDidEnd is called by the system, I add some data to the app's local CoreData store and sync that with the server. I use URLSession dataTask to make a POST request to my server, with URLSessionConfiguration.sharedContainerIdentifier set to my App Group's shared identifier. It is extremely rare that my server receives this request, although sometimes (rarely) it does. I've tried things like wrapping the task in performExpiringActivity or using URLSessionConfiguration.background suspecting that this task needs to run in the background, but none of it seems to work. What I suspect is happening is that the App Extension gets cancelled before the request is able to be invoked. Looking at the console logs, sometimes the work stops before the request is called, sometimes during the request task, and sometimes even before I am able to update my local data store. It's been v
I use App Groups to share UserDefaults data between my host app and DeviceActivityMonitor extension. On iOS 17, it appears that reading @AppStorage variables are causing my DeviceActivityMonitor extension callback functions to crash. Weirdly, writing values is okay. I see this in the extension logs: Couldn't read values in CFPrefsPlistSource<0x10fe251d0> (Domain: GROUP_NAME, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd However, through searching this log message on the internet and the fact that it also appears in my host app logs without crashing, this seems to be a warning - possibly indicating an issue but also a possible red herring. But the fact remains that when I don't read UserDefaults values or variables decorated with @AppStorage in the DeviceActivityMonitor extension, everything works fine. Are UserDefaults, and spe
Topic:
App & System Services
SubTopic:
Core OS
Tags:
iOS
Extensions
Managed Settings
Device Activity
Hello friends, I am working on an iOS app that uses the ScreenTime API to monitor app usage on the user's device. I am able to set up the monitoring schedule and start monitoring using code like this in the application: var calendar = Calendar.current let startDateComps = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: startDate) let endDateComps = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: endDate) let schedule = DeviceActivitySchedule(intervalStart: startDateComps, intervalEnd: endDateComps, repeats: false) let sessionName = DeviceActivityName(String(session.id)) do { try self.center.startMonitoring(sessionName, during: schedule) } catch { print(Could not start monitoring session (sessionName): (error)) } This appears to work. But in the DeviceActivityMonitor extension that I've added to the project, I never seem to get the init or intervalDidStart calls, and when I specify the DeviceActivityMonitor extension's scheme and try to debug it, XCod
Topic:
App & System Services
SubTopic:
General
Tags:
Extensions
Family Controls
Device Activity
Screen Time
I am still struggling to nail down the screen time between monitoring and showing it in a DeviceActivityReport. It's always off by a couple of percentage points, which results in a difference of a couple of minutes between the time shown for my total screen time in DeviceActivityReport and DeviceActivityMonitor with a threshold set for all apps/websites/categories. In the report, I am looping through all segment (there is only 1 segement using .daily segment interval for a given day) then loop through all categories and all apps within each category and sum up all totalActivityDuration for each app. Based on avaiable documentation, that should corrolate to DeviceActivityMonitor threshold but it doesn't. Are there any differences in how these 2 places count screen time? Are there any apps/core ios services which are excluded from DeviceActivityMonitor. Would appreciate any help at all, I'm losing my mind here. My current suspicion is that Apple Developer documentation is counted twic