Search results for

DeviceActivityMonitor

127 results found

Post

Replies

Boosts

Views

Activity

DeviceActivityMonitor is overcounting screen time for users on iOS 17.6.1
Our app uses a 24-hour DeviceActivityMonitor repeating schedule to send users notifications for every hour of screen time they spend on their phone per day. Notifications are sent from eventDidReachThreshold callbacks at 1, 2, 3, etc, hour thresholds to keep them aware of their screen time. We have recently received an influx of emails from our users that after updating to iOS 17.6.1 their DeviceActivityMonitor notifications are saying their screen time was much higher than what is shown in DeviceActivityReport and their device's Screen Time settings. These users have disabled Share Across Devices - but I suspect the DeviceActivityMonitor is still getting screen time from their other devices even though that setting is turned off. Has anybody else noticed this, understands what is causing this, or could recommend a fix that we can tell our users to do?
11
0
2.1k
Sep ’24
DeviceActivityMonitor event thresholds triggered together - what is the best way to log crashes / system terminations in the DeviceActivityMonitor extension?
I've been using DeviceActivityMonitor for 2 years, and recently noticed the following issue, starting in iOS 17.5 (another user also reported here). For a sizable percentage of my users, device activity event thresholds get triggered together. My app sends notifications for every hour of screen time during the DeviceActivitySchedule using event thresholds. Often users will get, for example, the 1, 2, and 3 hour screen time notifications all at the same time. I have a hypothesis for why this is happening: the system sometimes terminates the app extension for various reasons, one being if the 6MB memory limit is reached. It seems as though the retry policy is to retry the failed threshold at the next event threshold. And if the following threshold also fails, they can pile up until the next one succeeds. I think this is a new retry policy since iOS 17, and I believe this because: There used to be a bug where the same threshold was triggered multiple times in a row, indicating that the failed threshold
1
0
775
Aug ’24
How does the threshold in DeviceActivityEvent work
Hey everyone, I'm working on implementing an AppLimit, where after accumulating x minutes of Screen Time for an app, it should be blocked. It works fine on the first day, but stops functioning correctly on subsequent days. What I'm Doing I start a 24/7 schedule with a DeviceActivityEvent that has a specified Screen Time threshold. In my DeviceActivityMonitor, I'm reacting to the eventDidReachThreshold. Once the accumulated time is reached, the app is blocked. This works as expected on the first day. Issues I'm Experiencing / Questions Second Day Issue: On the second day, the app is no longer blocked after the Screen Time threshold is reached, even though it worked on the first day. This leads me to suspect that a DeviceActivityEvent is consumable. Is this correct? Pre-existing Screen Time Issue: If a user has already surpassed the Screen Time threshold before monitoring starts, the app isn't blocked once the schedule is set up. This leads to 2 issues: I would expect that the accumulated amount of tim
2
0
925
Aug ’24
Reply to Best way to pause DeviceActivitySchedule
I finally found a suitable solution, though it may not be the best approach. I'm storing the selection in shared UserDefaults with the Schedule ID as the key. This way, I can always retrieve the selected apps when I have the Schedule ID. This solved the problem of not having access to the apps that should be restricted. The other issue is actually pausing the monitoring, for which this solution is quite elegant: When the pausing action starts, all restrictions for this activity should be cleared, and the activity should no longer be monitored. Start a new activity with the identifier pause+(oldID) using the same selection and schedule times. The new schedule should contain a proper warningTime. Learn more about it here (it's not as simple as you might think): Apple Developer Documentation. In your DeviceActivityMonitor, your intervalDidStart(for activity:) function will now be called. But since the new schedule is started with the ID pause+(oldID), you can react to the name of the activity. You can n
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’24
Best way to pause DeviceActivitySchedule
Hi everyone, I'm currently working with the Screen Time API, specifically trying to figure out the best way to pause an active, repeating schedule without disrupting future schedules. Here's the scenario: I have a repeating schedule set from 10:00 AM to 8:00 PM daily. If I need to pause the schedule temporarily, my current approach involves stopping monitoring, clearing all restrictions, and then setting a new schedule for the remaining time after the pause. However, this method cancels the repeating schedule entirely, which causes issues when the schedule is supposed to restart the next day at 10:00 AM. Instead, it starts after the pause time, which isn’t what I want. Challenges I'm Facing: Maintaining Repeating Schedules: How can I pause the schedule in a way that ensures it resumes correctly the next day at the intended time (10:00 AM)? DeviceActivityMonitor Logic: Is there a way to deactivate and reactivate the schedule through the DeviceActivityMonitor without fully stopping the monitor
1
0
916
Aug ’24
Ending Live Activities When Timer Expires
Hi everyone, I'm working on an app that uses the Screen Time API, and I'm encountering an issue with Live Activities. The app runs a timer (e.g., 10 minutes), after which the intervalDidEnd method in DeviceActivityMonitor is triggered. To improve the user experience, I've implemented Live Activities to display the remaining time. However, I'm having trouble stopping the Live Activity when the timer expires and intervalDidEnd is called. It seems that the Screen Time extensions cannot detect or interact with active Live Activities, even though both share the same App Group. My Question: Since the DeviceActivityMonitor extension does not seem to be able to detect Live Activities, does anyone know if there’s a way to end a Live Activity when the timer expires without relying on a server? Using Apple’s Push Notification service feels excessive given the lightweight nature of the app, which doesn’t use server-side components. Any insights or suggestions would be greatly appreciated! Thanks!
1
0
1.1k
Aug ’24
Failed to fetch a usage budget
Hello! I'm trying to build an app that incorporates the screentime API using a DeviceActivityMonitor extension. I've found a couple public repo's accomplishing what I'm trying to make. When cloning, editing identifiers and app groups, I keep getting this error message when trying to execute the DeviceActivityMonitorExtension Error: Error Domain=UsageTrackingErrorDomain Code=101 Failed to fetch a usage budget UserInfo={NSLocalizedDescription=Failed to fetch a usage budget, NSLocalizedRecoverySuggestion=See Console for additional details.} In mac console it does not show further details, just the same error message lol. This happens on my app as well that was built from scratch under my own identifiers etc. It only occurs when trying to make a call to the extension. I believe my PLists and entitlements are properly setup but I still get this error. The screentime API has been out for a while now and I can't seem to find an answer to my question. I've been trying to battle this for weeks now does anyone
0
0
328
Aug ’24
[iOS 18 Beta 4] DeviceActivityMonitor extension is more likely to deadlock
Hi there, My app uses all the Screen Time API's with individual FamilyControls authorization. I've been using the API's for over 2 years (since they came out). In iOS 18 Beta (maybe started in Beta 3?), I've been experiencing random issues. I tracked it down to where it seems like DeviceActivityMonitor extension is more likely to deadlock in iOS 18. To reproduce: when DeviceActivityMonitorExtension.intervalDidEnd gets called, IF you call DeviceActivityCenter.startMonitoring for that SAME DeviceActivityName from the DeviceActivityMonitorExtension , the startMonitoring call deadlocks (if I pause debugger, it does not advance past DeviceActivityCenter.startMonitoring). The bug is reported in FB14664238. It also contains a sample project where you can reproduce this. I also note in the comment section that this is not the only way to encounter this problem. My application code (which is a lot more complicated) seems to deadlock on calling DeviceActivityCenter.activities. As a result, there seems to be an
1
0
842
Aug ’24
Reducing Memory Usage in DeviceActivityMonitor: Help Needed
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!
1
0
663
Jul ’24
Reply to The DeviceActivityMonitor did not trigger a callback
Below is all the code; the method intervalDidStart has never been called. Can you help me? import UIKit import MobileCoreServices import ManagedSettings import DeviceActivity class MyMonitor: DeviceActivityMonitor { let store = ManagedSettingsStore() override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) print(interval did start) let model = MyModel.shared let applications = model.selectionToDiscourage.applicationTokens store.shield.applications = applications.isEmpty ? nil : applications store.appStore.maximumRating = 200 } override func intervalDidEnd(for activity: DeviceActivityName) { super.intervalDidEnd(for: activity) store.shield.applications = nil store.clearAllSettings() } } // // MyModel.swift // FamilyCotrol // // Created by mac on 2024/6/24. // import UIKit import Foundation import FamilyControls import DeviceActivity import ManagedSettings class MyModel: ObservableObject { static let shared = MyModel() let store = ManagedSettingsStore() p
Topic: App & System Services SubTopic: General Tags:
Jun ’24
The DeviceActivityMonitor did not trigger a callback
The listening callbacks were not triggered for intervalDidStart and intervalDidEnd after successfully starting center.startMonitoring when I attempted to set a schedule with DeviceActivitySchedule at 20-minute intervals Is there anyone who can assist me? Thank you. Below you will find my code. let intervalLengthInSeconds = 20 * 60 let intervalEnd = Date(timeIntervalSinceNow: TimeInterval(intervalLengthInSeconds)) let intervalStart = Date() let schedule = DeviceActivitySchedule(intervalStart: Calendar.current.dateComponents([.hour, .minute], from: intervalStart), intervalEnd: Calendar.current.dateComponents([.hour, .minute], from: intervalEnd), repeats: false, warningTime: DateComponents(minute: 1)) let newActivity = DeviceActivityName(rawValue: 20minuteUse) Log(😯 (String(describing: schedule.nextInterval))) do { try center.startMonitoring(newActivity, during: schedule) } catch { print(failed to start session: (error.localizedDescription)) } class MyMonitorExtension: DeviceActivityMonitor { let store
2
0
801
Jun ’24
Inconsistency in the DeviceActivityEvent callbacks
We are using the Apple ScreenTime API for monitoring the usage of device. As mentioned in the documentation (https://developer.apple.com/documentation/familycontrols), we are getting the family controls authorisation from the user. We also have added the ‘DeviceActivityMonitor’ app extension (https://developer.apple.com/documentation/deviceactivity/deviceactivitymonitor) to receive the schedule and event callbacks. We have a requirement in which we have to notify the user for every 15 minutes usage of the device in the specified interval. He can optionally select individual categories or applications for the 15 minutes notification. For monitoring the usage for individual categories or applications, we obtain the token by presenting the FamilyActivityPicker as discussed in this documentation https://developer.apple.com/documentation/familycontrols/familyactivitypicker. For simplicity in testing during the development phase, we reduced the 15 minutes to 2 minutes. The events callbacks are exp
3
0
959
Jun ’24
Device activity extensions is never getting called.
I added debug break point to the first line of MyDeviceActivityMonitor.swift, it never got trigger. I am able to launch the app, select discouraged and encouraged app. discouraged apps are getting restricted which is expected. but device activity extension is never called. I have all the permission and certificate. I created an app group. import SwiftUI import FamilyControls import ManagedSettings @main struct GetALifeApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate @StateObject var model = MyModel.shared @StateObject var store = ManagedSettingsStore() var body: some Scene { WindowGroup { ContentView() .environmentObject(model) .environmentObject(store) } } } class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { initiateAsyncSetup() MySchedule.setSchedule() return true } private func initiateAsyncSetup() { Task { do { try await
1
0
740
May ’24
Device activity extension not being called.
I am new to swift. This is my first app. What an i doing wrong. Device activity monitor extension is never being called. When i launch the app, I am able to pick the discouraged and encouraged apps. It immediately restrict the discouraged app which is expected. But the extension is never called. import SwiftUI import FamilyControls import ManagedSettings @main struct GetALifeApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate @StateObject var model = MyModel.shared @StateObject var store = ManagedSettingsStore() var body: some Scene { WindowGroup { ContentView() .environmentObject(model) .environmentObject(store) } } } class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { initiateAsyncSetup() return true } private func initiateAsyncSetup() { Task { do { try await AuthorizationCenter.shared.requestAuthorization(for: .individual) MyS
0
0
723
May ’24