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 = DeviceActivityCenter()
func scheduleTestActivity(startDate: Date, endDate: Date) {
let calendar = Calendar.current
let startComponents = calendar.dateComponents([.hour, .minute], from: startDate)
let endComponents = calendar.dateComponents([.hour, .minute], from: endDate)
// Tworzymy schedule
let schedule = DeviceActivitySchedule(
intervalStart: startComponents,
intervalEnd: endComponents,
repeats: true
)
do {
try center.startMonitoring(.daily, during:schedule)
print("startMonit /(\(schedule))")
} catch {
print("ghfgh")
}
}
}
struct TestView__Previews: PreviewProvider {
static var previews: some View {
TestView_()
}
}
DeviceActivityMonitor target:
// BlockingAppsMonitorExtension
//
// Created by on 10/01/2025.
import DeviceActivity
import FamilyControls
import ManagedSettings
import os
let logger = Logger()
public class BlockingAppsMonitor: DeviceActivityMonitor {
private let store = ManagedSettingsStore()
public override func intervalDidStart(for activity: DeviceActivityName) {
super.intervalDidStart(for: activity)
print("Rozpoczęcie interwału blokowania \(activity.rawValue)")
logger.info("intervalDidStart")
startBlocking()
}
public override func intervalDidEnd(for activity: DeviceActivityName) {
super.intervalDidEnd(for: activity)
print("Zakończenie interwału blokowania \(activity.rawValue)")
logger.info("intervalDidend")
stopBlocking()
}
@discardableResult
private func startBlocking() -> Int {
print("number of unique apps")
return 51
store.shield.applicationCategories = .all()
// return exceptions.count
}
private func stopBlocking() {
store.shield.applicationCategories = nil
store.shield.applications = nil
}
}
INB4:
In both files are added family controls
Secent file is added in DeviceActivityMonitor target.
Apple answer please?
Prevent access to the Screen Time API without guardian approval and provide opaque tokens that represent apps and websites.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
When we request auth from the AuthorizationCenter, it seems that we're only really able to allow users to control the apps on the parent's phone. Is there a way to allow us to let parents manage apps on the kid's device directly through our parent app?
For context, we have 2 different apps, one for the parent and one for the child. The child is able to purchase screen time and the parent can redeem them (activate those minutes) from their end.
Hello Apple development team, I have developed an App for screen time management, which mainly uses ScreenTimeAPI. Users can set certain Apps to be disabled during a certain period of time.
After the App is released, users often report that the settings do not take effect as expected. I have seen many developers on the forum reporting that the DeviceActivityMonitor extension sometimes does not trigger callbacks. Based on this background, I have the following questions:
Is it a known problem that the DeviceActivityMonitor extension sometimes does not trigger callbacks? If so, are there any means to avoid or reduce the probability of occurrence?
In addition to being killed by the system when the running memory exceeds (I just called some ScreenTimeAPI and accessed UserDefaults in the extension, which should not exceed the running memory), under what other circumstances will the DeviceActivityMonitor extension be killed by the system? Will it automatically recover after being killed? Will some callbacks be called when killing?
Does ManagedSettingsStore have a life cycle? How do you avoid conflicts when configuring the underlying operating mechanism of multiple stores?
This is a random problem. I have never encountered it during development and debugging, but users often report it.
thanks
Topic:
App & System Services
SubTopic:
General
Tags:
Family Controls
Device Activity
Managed Settings
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, .month, .day, .hour, .minute, .second], from: Date().addingTimeInterval(1.0))
dateComponents.calendar = Calendar.current
dateComponents.timeZone = TimeZone.current
// Create the trigger as a repeating event.
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
let uuidString = UUID().uuidString
let request = UNNotificationRequest(identifier: uuidString, content: content, trigger: trigger)
// Schedule the request with the system.
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request)
}
}
And this is the method that is starting the monitoring session:
@objc public static func startSession() -> String? {
// Calculate start and end times
let center = DeviceActivityCenter()
let minutes = 15
let startDate = Date().addingTimeInterval(1)
guard let endDate = Calendar.current.date(byAdding: .minute, value: minutes, to: startDate) else {
return "Failed to create end date?"
}
// Create date components and explicitly set the calendar and timeZone
let startComponents = Calendar.current.dateComponents([.era, .year, .month, .day, .hour, .minute, .second], from: startDate)
let endComponents = Calendar.current.dateComponents([.era, .year, .month, .day, .hour, .minute, .second], from: endDate)
// Create schedule
let schedule = DeviceActivitySchedule(
intervalStart: startComponents,
intervalEnd: endComponents,
repeats: false
)
print("Now", Date())
print("Start", startDate, startComponents)
print("End", endDate, endComponents)
print(schedule.nextInterval)
do {
// Use a consistent activity name for our simple implementation
let activity = DeviceActivityName("SimpleSession")
try center.startMonitoring(activity, during: schedule)
return nil
} catch {
return "Failed to start monitoring: \(error)"
}
}
I can confirm my dates & date components make sense with the 4 print statements. Here is the output:
Now 2025-02-12 04:21:32 +0000
Start 2025-02-12 04:21:33 +0000 era: 1 year: 2025 month: 2 day: 11 hour: 20 minute: 21 second: 33 isLeapMonth: false
End 2025-02-12 04:36:33 +0000 era: 1 year: 2025 month: 2 day: 11 hour: 20 minute: 36 second: 33 isLeapMonth: false
Optional(2025-02-12 04:21:33 +0000 to 2025-02-12 04:36:33 +0000)
I get the Session activated! notification but never get the Session ended notification. Half an hour later, I've tried debugging the DeviceActivityCenter by printing out the activities property and can see that it is still there. When I try to print out the nextInterval property on the schedule object i get from calling center.schedule(for:), it returns nil.
I'm running this on an iPhone 8 testing device with developer mode enabled. It has iOS 16.7.10. I'm totally lost as to how to get this to work.
Hi there,
I am planning an app that requires use of the Family Controls Entitlement to access data on the user's screen time.
I understand that this has to be requested from Apple before it can be used in production.
I have found the following form to request approval, but it requires an App and bundle ID, which suggests that approval can only be requested after the app has been developed.
https://developer.apple.com/contact/request/family-controls-distribution
I'd like to avoid the situation where I spend a lot of time on developing the app, only to find out that the Family Controls Entitlement will not be granted for my use case.
Is there any way that I can request provisional pre-approval for my app? Perhaps based on an app description and some mockups? Or, at least some idea of whether my particular use case is likely to be approved?
Thanks.
I am developing a parental control app using Apple’s Screen Time API and FamilyControls Framework. My goal is to allow parents to remotely block apps on their child’s device from their own phone. Does anyone have any idea how I can achieve that?
Topic:
App & System Services
SubTopic:
General
Tags:
Family Controls
Device Activity
Managed Settings
I am developing a parental control app using Apple’s Screen Time API and FamilyControls Framework. My goal is to allow parents to remotely block apps on their child’s device from their own phone. Anyone have any idea how can i do that?
Topic:
App & System Services
SubTopic:
General
Tags:
Family Controls
Device Activity
Managed Settings
I'm at my wit's end here with an iOS app I'm developing. I've applied for the Family Controls entitlement, and while my extensions (like Device Monitor) have been accepted, the main target entitlement for my app still hasn't been approved.
Here's the timeline:
Extensions (Device Monitor etc.): Accepted about a month ago. Main App Entitlement: Still pending - it's been over 6 weeks now. I'm looking for:
Anyone who has gone through this process and can share how long it took for their main app entitlement to get approved after the extensions were. Any tips on what might speed up the process or what I might be doing wrong. Experiences with contacting Apple Developer Support regarding this issue.
If you've been through a similar ordeal or have any advice, I'd really appreciate it. Thanks for any help or insight you can offer!
I'm currently running into an issue during the App Store review process where my reviewer isn't liking how the Screen Time API is being used to hide apps.
For some context, my app uses the Managed Settings and Device Activity frameworks in the Screen Time API to allow users to set restrictions on their personal devices and save those restrictions into a preference object that they can switch between. This was detailed as my app's primary purpose in my Family Controls & Personal Device Usage Entitlement Request, which was approved last year.
After around a year of working on this app, it's finally done and ready for submission to the App Store. However, my App Reviewer recently rejected the app with this single complaint:
Guideline 2.5.1 - Performance - Software Requirements
The app uses public APIs in an unapproved manner, which does not comply with guideline 2.5.1.
Specifically, your app uses ScreenTime API to hide apps.
Since there is no accurate way of predicting how an API may be modified and what effects those modifications may have, unapproved uses of public APIs in apps is not allowed.
Next Steps
Please revise the app to ensure that documented APIs are used in the manner prescribed in the documentation.
All I'm doing is passing a set of Application objects to ManagedSettings.ApplicationSettings.blockedApplications, I'm not doing anything special. The documentation for this API itself states:
The system hides blocked applications and prevents the user from launching them.
In my reply, I let the reviewer know
Regarding Guideline 2.5.1, I believe my use of the Screen Time API appears to align with Apple's documented intended functionality. The specific API I'm using, ManagedSettings.ApplicationSettings.blockedApplications, is explicitly documented by Apple as: "The system hides blocked applications and prevents the user from launching them."
This is why I used the term "hide" in my app's marketing and functionality descriptions - I was directly referencing Apple's own terminology for this feature. The documentation clearly indicates this is an approved capability of this API.
The source for this documentation can be found here: https://developer.apple.com/documentation/managedsettings/applicationsettings/blockedapplications-swift.property. I've also provided a screenshot of this documentation below.
Despite providing a link to the documentation and a screenshot that shows the text from Apple explicitly stating "The system hides blocked applications", the App Reviewer just copy-and-pasted the same text in their reply and rejected the app.
I should also note that we don't have control over how the system handles the Application set we pass into ManagedSettings.ApplicationSettings.blockedApplications, the system will always try to "hide" these apps as specified in the documentation. We can't change this behavior.
Has anyone else faced this sort of rejection before? Is using ManagedSettings.ApplicationSettings.blockedApplications now considered an illegal use of the API? Or are we not allowed to use the words noted in the documentation of this API? The app rejection suggested I "consult with fellow developers and Apple engineers on the Apple Developer Forums." Any guidance here would be much appreciated as I continue to appeal this. For any Apple staff members reading this post, I can provide the Submission ID of the App Review privately if needed to help resolve this issue.
Topic:
App Store Distribution & Marketing
SubTopic:
App Review
Tags:
App Review
Family Controls
Managed Settings
Screen Time
tl;dr can we use Label(application token) inside of a DeviceActivityReport?
I’m working on an app that uses the DeviceActivityReport extension to show a user’s screen time breakdown. The app was working fine in a setup where my main app had the Distribution Family Controls capability and all the extensions had the Development Family Controls capability. However, this caused provisioning issues when I tried to create a test flight build.
I then removed the development capabilities from the extensions, and now everything works fine except oddly the Labels in the DeviceActivityReport no longer show anything. They worked fine before, and the same label logic is working 100% fine inside my main app.
Anyone encounter this before?
When adding a ShieldConfigurationExtension AppExtension target, the FamilyControls capability is automatically added. If this capability is not needed for the target, will removing it cause any issues during the App Store review process?
How to display DeviceActivityReportScene in a widget.
When I was developing a widget, I found that DeviceActivityReportScene could not be displayed in the widget.
Hi all,
I’ve run into a frustrating issue with the FamilyControls and DeviceActivityMonitor APIs.
I’ve received official approval from Apple to use the com.apple.developer.family-controls entitlement (distribution), and I’ve added the entitlement to both my main app and the DeviceActivityMonitor extension. I’ve also ensured the correct App Group is configured for both targets.
Everything works perfectly when I install the app on my own device as an internal TestFlight tester. App blocking works, the DeviceActivityMonitor extension runs as expected, and the apps selected by the user are correctly shielded.
However, for external TestFlight testers, while they do receive the Screen Time permission prompt, and can select apps to block, nothing actually gets blocked. It appears that the DeviceActivityMonitor extension is not being triggered at all on their devices.
I’ve verified the following:
The entitlement is approved and visible in App Store Connect
The build is approved for external testing
Testers are running iOS 16+
Shielding logic works properly on internal tester devices
Clean installs have been tested on external devices
Has anyone gotten FamilyControls + DeviceActivityMonitor working successfully for external testers via TestFlight?
If this is a known limitation or if there are any additional steps required to enable extension execution for external users, I’d really appreciate any clarification.
Thanks in advance for your help.
Topic:
App Store Distribution & Marketing
SubTopic:
TestFlight
Tags:
TestFlight
Testing
Family Controls
So I have been working with the screen time api. however I still cant get it to work to reshield certain apps after a certain time because for example Dispatch Queue just gets terminated after a certain time.
This is my code right now but the reshielding doesn't get called. Please help I have been working on this since weeks and weeks.
import ManagedSettings
import DeviceActivity
import Foundation
class ShieldActionExtension: ShieldActionDelegate {
let store = ManagedSettingsStore()
let center = DeviceActivityCenter()
override func handle(action: ShieldAction, for application: ApplicationToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
switch action {
case .primaryButtonPressed:
// Unshield the app
store.shield.applications?.remove(application)
// Encode and persist ApplicationToken
if let encoded = try? PropertyListEncoder().encode([application]) {
UserDefaults(suiteName: "group.Organization.BrainRipe.cmonnow")?.set(encoded, forKey: "StoredApplicationTokens")
}
let unshieldDurationMinutes = 2
let now = Date()
guard let endDate = Calendar.current.date(byAdding: .minute, value: unshieldDurationMinutes, to: now) else {
completionHandler(.close)
return
}
let activityName = DeviceActivityName("com.myapp.shield.reapply")
let schedule = DeviceActivitySchedule(
intervalStart: Calendar.current.dateComponents([.hour, .minute], from: now),
intervalEnd: Calendar.current.dateComponents([.hour, .minute], from: endDate),
repeats: false
)
do {
try center.startMonitoring(activityName, during: schedule)
} catch {
print("Error starting monitoring: \(error)")
}
completionHandler(.close)
case .secondaryButtonPressed:
completionHandler(.defer)
@unknown default:
fatalError("Unhandled ShieldAction case.")
}
}
}
import DeviceActivity
import ManagedSettings
import Foundation
// Optionally override any of the functions below.
// Make sure that your class name matches the NSExtensionPrincipalClass in your Info.plist.
class DeviceActivityMonitorExtension: DeviceActivityMonitor {
let store = ManagedSettingsStore()
override func intervalDidStart(for activity: DeviceActivityName) {
super.intervalDidStart(for: activity)
// Handle the start of the interval.
}
override func intervalDidEnd(for activity: DeviceActivityName) {
guard let data = UserDefaults(suiteName: "group.Organization.BrainRipe.cmonnow")?.data(forKey: "StoredApplicationTokens"),
let tokens = try? PropertyListDecoder().decode([ApplicationToken].self, from: data) else {
return
}
let tokenSet = Set(tokens)
if store.shield.applications == nil {
store.shield.applications = tokenSet
} else {
store.shield.applications?.formUnion(tokenSet)
}
// Clear tokens after use
UserDefaults(suiteName: "group.Organization.BrainRipe.cmonnow")?.removeObject(forKey: "StoredApplicationTokens")
}
}
Topic:
App & System Services
SubTopic:
General
Tags:
SwiftUI
Family Controls
Managed Settings
Screen Time
Hi all,
I'm working on a Screen Time-based app with gamification features for families, where both children and parents interact and compare usage stats. The endgoal of the app is to motivate for less screentime or more use of productive apps. I'm testing Apple's Family Controls API, which works great for getting data from child devices. However, this API doesn't support fetching screen time data on the parent device itself.
Apps like Jomo appear to provide insights and even their own "calculations" on screen time usage directly on the parent device. I have tested a few apps that showed both the usage data for my children and myself and did some nice things with it like creating stats. I've gone through the documentation and APIs extensively, but I can’t figure out how they’re doing this.
As far as I can tell the only solution would be a custom VPN or MDM. However as far as I can tell Jomo for example does not use either of those.
My questions are:
Am I missing some API
Are apps like Jomo using private APIs which they have been granted access to from Apple?
Is there any way to access similar data on a parent device without using MDM or VPN?
Any guidance or clarification would be greatly appreciated!
I have been approved for family controls entitlements and see them in my apple certificates for my bundle identifier. I see them listed for Distribution in my Runner, however, when I try to distribute I get the error that I do not have the right permissions. Do I need to get the entitlements for each extension I have as well? I have three extensions that use the family controls.
An error was reported when requesting permissions on devices with iOS 16.2 16.3. It is not an emulator.
Through the log records, the following Error message appears
Error Domain=FamilyControls.FamilyControlsError Code=3 "(null)"
Error Domain=FamilyControls.FamilyControlsError Code=4 "(null)"
Error Domain=FamilyControls.FamilyControlsError Code=5 "(null)"
func requestScreenTime() async -> Bool {
do {
try await AuthorizationCenter.shared.requestAuthorization(for: .individual)
return AuthorizationCenter.shared.authorizationStatus == .approved
} catch {
print("\(error)")
return false
}
}
Cannot convert value of type '[ApplicationToken]' (aka 'Array<Token>') to expected argument type 'Binding'
For an iOS app that runs in both child and parent mode across iOS devices. On the child device, with Family Controls enabled using .child permissions via AuthorizationCenter.requestAuthorization(for: .child).
Is any way to display a list of recently used apps by the child on the parent (guardian) device, in a privacy-preserving and Apple-compliant way?
Hi everyone,
I’m experimenting with the new ScreenTime DeviceActivityReport view in SwiftUI (iOS 17 / Xcode 15).
My goal is to show the report inside a Button (or, more generally, capture any tap on it) so that I can push a detail screen when the user selects it.
Here’s the minimal code that reproduces the issue:
import FamilyControls
import DeviceActivity
import SwiftUI
struct ScreenTimeView: View {
let center = AuthorizationCenter.shared
@State private var context: DeviceActivityReport.Context =
.init(rawValue: "Total Activity")
@State private var filter = DeviceActivityFilter(
segment: .hourly(
during: Calendar.current.dateInterval(of: .day, for: .now)!
),
users: .all,
devices: .init([.iPhone, .iPad])
)
var body: some View {
ZStack {
DeviceActivityReport(context, filter: filter)
}
.onAppear {
Task {
do {
try await center.requestAuthorization(for: .individual)
} catch {
print("Authorization failed:", error)
}
}
}
}
}
struct ContentView: View {
var body: some View {
ScrollViewReader { _ in
ScrollView(showsIndicators: false) {
VStack {
Button {
print("BUTTON TAPPED") // ← never fires
} label: {
ScreenTimeView()
.frame(height: UIScreen.main.bounds.height * 1.4)
}
}
}
}
}
}
**
What happens**
DeviceActivityReport renders correctly with hourly bars.
Tapping anywhere inside the Button does not trigger print("BUTTON TAPPED").
I’ve tried replacing Button with .onTapGesture, adding .contentShape(Rectangle()), and .allowsHitTesting(true), but nothing registers.
What I’ve checked
Authorisation succeeds—calling code in .onAppear prints no errors.
Removing DeviceActivityReport and replacing it with a plain Rectangle() lets the tap gesture fire, so the issue seems specific to DeviceActivityReport.