Search results for

DeviceActivityMonitor

127 results found

Post

Replies

Boosts

Views

Activity

shielding and blocking apps
i'm trying to shield and block apps on child device. i managed to block apps by creating a variable blockedApps : Set = Set() that contains a list of applications like Application(bundleIdentifier: com.apple.calculator) inside the intervalDidStart on my DeviceActivityMonitor extension now i'm trying to shield an app using the same extension and nothing happens. for this i used this code inside intervalDidStart: let calculatorApp = Application(bundleIdentifier: com.apple.calculator) var blockedApps : Set = Set() guard let token = calculatorApp.token else { return } blockedApps = [token] store.shield.applications = blockedApps and i cant tell what is the reason for this not working is there a token issue that is nil? does shielding requires a different app extension? does my app extension requires some additional configuration maybe a different NSExtensionPointIdentifier?
2
0
3k
Nov ’21
Family Controls (Distribution) was granted to main bundle ID, but not to the extensions
I've successfully obtained Distribution entitlements for Family Controls. However, this seems to only apply to the main target/identifier and not the extensions, like DeviceActivityMonitor, ShieldConfigurationDataSource, or ShieldActionExtension. Did I perhaps fill out the form with the wrong bundle ID? If I go to Certificates, Identifiers & Profiles, my main identifier for the app has the Distribution entitlement. But the extensions and the wildcard don't. This means that trying to create an archive results in the following two errors, each repeated twice: Provisioning profile failed qualification (Profile doesn't support Family Controls (Development)) Provisioning profile failed qualification (Profile doesn't include the com.apple.developer.family-controls entitlement) Note that my entitlement files are set up correctly. Do I need to fill out the form with a wildcard instead? Or am I doing something wrong? Thank you.
3
0
731
Feb ’25
Family Controls Approved for Main App but Not Extension – Blocking
Hi everyone, I’m developing a screen-time and focus app that uses Apple’s Family Controls framework to block distracting apps and reward users through a gamified experience. Apple approved Family Controls (Distribution) for the main app identifier, but they did not approve the required extension target (which implements DeviceActivityMonitor, required for the framework to function). Because of this, I can’t archive or upload the app to TestFlight — and I’ve been stuck in limbo for over 2 months. This is severely delaying my launch. The app works perfectly, but I can’t release it because the extension wasn’t included in the entitlement approval. Has anyone else run into this with Family Controls? Is there any known way to escalate or fast-track approval for additional app IDs or targets? Would really appreciate any help, advice, or hacks. 🙏 Thanks, Enzer
0
0
112
Apr ’25
DeviceActivityEvent will still execute even if the app is not in use
I use DeviceActivityCenter to monitor app usage. For DeviceActivityEvent, I set 30 events, and the threshold of each event increases by 2 minutes: var events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [:] for index in 0..<30 { let threshold = (index == 29) ? DateComponents(hour: 1) : DateComponents(minute: (index + 1) * 2) let name = DeviceActivityEvent.Name((prefix)|(index)) events[name] = DeviceActivityEvent(applications: tokens, threshold: threshold) } After reaching the last DeviceActivityEvent, I will restart directly in DeviceActivityMonitor private func restartMonitoring(activity: DeviceActivityName) { let center = DeviceActivityCenter() let currentEvents = center.events(for: activity) do { try center.startMonitoring(activity, during: schedule, events: currentEvents) } catch { print(Fail: (error)) } } But I found that after restarting, DeviceActivityEvent will be automatically executed even if I don't use the app. My iOS version is 18.5
0
0
121
Jun ’25
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
Family Controls application-identifier Entitlement error while blocking an application
I was able to start the device activity monitor. I was able to see the Device Activity Monitor Extension as a process, and was able to attach to it via Xcode. Now I am trying block a specific 3rd party application, via the Shield. I am using this piece of code for intervalDidStart : override func intervalDidStart(for activity: DeviceActivityName) { NSLog(Interval started for Device Activity) let blockedApps : Set = [Application(bundleIdentifier: com.facebook.Facebook)] store.application.blockedApplications = blockedApps super.intervalDidStart(for: activity) } I've declared store in the DeviceActivityMonitor class as follows : let store = ManagedSettingsStore() This is the error I see in the Console: Error Domain=UsageTrackingErrorDomain Code=1 Something without a application-identifier entitlement tried to manage usage budgets UserInfo={NSLocalizedDescription=Something without a application-identifier entitlement tried to manage usage budgets} The above use case should work right? I should be able to
6
0
3.1k
Jun ’21
eventDidReachThreshold triggered while target app is in background
Hello! I am using the eventDidReachThreshold callback in the DeviceActivityMonitor in order to shield a target app after the user has spend x amount of time on it (e.g. x = 5 minutes). Many times this works fine, and I can trigger my shield after the specified threshold has been met. However sometimes, when they leave the target app before the threshold has been reached, the eventDidReachThreshold callback gets called randomly while they are doing something else on their phone (e.g. using a different app, on the Home Screen, phone locked…). From my perspective this does not make sense, since they are not actively spending time on the target app, and that time should not be counted towards the target app’s threshold. And it is also very confusing for the users because they will then find a blocked target app even though they haven’t used their time budget completely. This is not related to the intervalDidStart / intervalDidEnd callbacks, because they are not correlating with the timing of when the eve
0
0
667
Mar ’24
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
ScreenTime API
Can the Screen Time API in iOS be used to block specific applications or application categories from getting launched? I went through the documentation here: https://developer.apple.com/videos/play/wwdc2022/110336/ and it indicates that we should be able to block certain app categories using the DeviceActivity and FamilyControl Framework. So, I created the following code snippet: class DeviceActivityMonitorExtension: DeviceActivityMonitor { let store = ManagedSettingsStore() override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) NSLog(interval did start) let model = MyModel.shared let applications = model.selectionToDiscourage.applicationTokens store.shield.applications = applications.isEmpty ? nil : applications store.dateAndTime.requireAutomaticDateAndTime = true } And made a class model var selectionToDiscourage = FamilyActivitySelection() { willSet { NSLog (got here (newValue)) let applications = newValue.applicationTokens let categories = newValu
2
0
3.1k
Sep ’22
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
Schedule Task (Screen Time API) on iOS in background mode
I have developed a Flutter application to lock selected apps using the Screen Time API (iOS). My app has been registered in Family Control and currently successfully executes app restrictions in both emulators and devices through TestFlight. I intend to incorporate a countdown timer feature to ensure that the app restriction function is activated when the timer stops (e.g 15 minutes after function called). However, the issue I'm facing is that on iOS, when the app goes into the background mode, all processes, including the countdown, halt, rendering the restriction function unusable. I have attempted various mechanisms, such as: DeviceActivityMonitor extension => Not triggered even though DeviceActivitySchedule is set. Cron => Stops when in background mode. Local notification => Only triggered when the user interacts with the notification, not automatically execute function in background Is there a solution to address this matter? Here is my snippet code, startAppRestrictions() is already wo
1
0
1.7k
Aug ’23
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
Family Controls Issues with Multiple Functionalities
I am developing an application that utilizes Family Controls to restrict the use of certain apps. Currently, I am using the following extensions: DeviceActivityMonitor, ShieldConfiguration, and ShieldAction. Issue Overview: While blocking a single application functions correctly, a problem arises when implementing multiple functionalities that use these extensions for the same application. STEPS TO REPRODUCE Functionality 1: Maximum Time in App Description: Blocks the app after 15 minutes of continuous use. Functionality 2: Conscious Opening Description: Upon opening the app, it is blocked for 10 seconds and then automatically unlocked. Steps to Reproduce the Bug: Open the Application: The app opens normally. Trigger Functionality 2 The app is blocked and displays the blocking screen corresponding to Functionality 2: Conscious Opening. Continue Using the App After 10 seconds, the app unlocks, and I continue using it. Important: If the app is closed at this point, the bug does not occur. Trigger Funct
0
0
312
Dec ’24
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
DeviceActivityMonitor.intervalDidEnd never getting called
I'm trying to build an app with a DeviceActivityMonitor extension that executes some code after 15 minutes. I can confirm that the extension is set up correctly and that intervalDidStart is executed, but for some reason the intervalDidEnd method never gets called. What I'm doing in both is just registering a local notification. class DeviceActivityMonitorExtension: DeviceActivityMonitor { let store = ManagedSettingsStore() override func intervalDidStart(for activity: DeviceActivityName) { createPushNotification( title: Session activated!, body: ) super.intervalDidStart(for: activity) } override func intervalDidEnd(for activity: DeviceActivityName) { createPushNotification( title: Session ended, body: ) super.intervalDidEnd(for: activity) } private func createPushNotification(title: String, body: String) { let content = UNMutableNotificationContent() content.title = title content.body = body // Configure the recurring date. var dateComponents = Calendar.current.dateComponents([.era, .year,
1
0
409
Feb ’25