Hello fellow Screen Time Fans!
I am encountering a strange problem since I started working with the Screen Time framework, and I don’t know what I’m doing wrong:
Imagine the app has two ManagedSettingsStores:
one to block apps during work hours (let’s say from 9am to 5pm) and one to block apps in the evening (let’s say from 5:30pm till midnight).
Imagine, the user has blocked Instagram in both.
When the user has Instagram open at 4:59pm it shows the Block during Work Hours Shield (so far, so good).
At 5pm, the shield is removed, and the user can use Instagram.
Then, at 5:30 the a shield is activated again: this time, the Instagram token is added to the evening store.
However, there is no new ShieldConfiguration requested from the ShieldConfigurationDataSource.
Instead, the previous shield from the work hour block is re-used and shown.
To me, it appears that the Framework does not request new shields, when the token is moved from one store to another while the app remains in foreground.
The Shield is only re-rendered when the user closes the shielded app and re-opens it.
This is really confusing behavior and I would like to fix it.
Did anyone here encounter something similar, and has a suggestion or workaround?
My feedback is also documented in FB14237883.
Screen Time
RSS for tagShare and manage web-usage data, and observe changes made to Screen Time settings by a parent or guardian.
Posts under Screen Time tag
132 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I need some assistance with the Screen Time API’s DeviceActivityReport extension. I know the extension is sandboxed but I need the data inside my app. Jomo is currently doing this so it’s not impossible. I see they’re saying it’s an estimate which is about 5 - 10 off of the actual screen time, but how are they doing this?
Any attempt to store the screen time data inside some sort of database or UserDefaults always fails of course due to the sandbox.
Any advice would be greatly appreciated!
Hello, I'm currently facing some technical difficulties in implementing features related to application restrictions using the ScreenTime API.
In our app, we allow users to set up restrictions for specific apps and app categories, with scheduled times and days (for example, Mondays and Thursdays, from 2pm to 5pm). The blocking sessions must run independently and simultaneously, allowing different sets of applications to be restricted at different times. However, I ran into two main problems:
1. Applying restrictions in the DeviceActivityMonitor extension:
Although I can enable and disable restrictions, I haven't found an effective way to apply multiple FamilyActivitySelections directly in the DeviceActivityMonitor extension. The extension has to manage different blocking sessions independently, restricting different sets of applications and categories simultaneously or separately.
I would like to know if it is possible to transmit this list of selected applications via UserDefaults or CoreData to the extension in order to facilitate this integra
To better illustrate, here is a snippet of the code I am using:
import Foundation
import FamilyControls
import ManagedSettings
import DeviceActivity
class AppBlockManager: ObservableObject {
private let store = ManagedSettingsStore()
private let center = DeviceActivityCenter()
@Published var activitySelection: FamilyActivitySelection
private var activityName: DeviceActivityName
private var schedule: DeviceActivitySchedule
init(selection: FamilyActivitySelection, activityName: DeviceActivityName, schedule: DeviceActivitySchedule) {
self.activitySelection = selection
self.activityName = activityName
self.schedule = schedule
}
func startBlock() {
do {
try center.startMonitoring(activityName, during: schedule)
if let applications = activitySelection.applications.isEmpty ? nil : activitySelection.applicationTokens {
store.shield.applications = applications
}
if let categories = activitySelection.categories.isEmpty ? nil : activitySelection.categoryTokens {
store.shield.applicationCategories = ShieldSettings
.ActivityCategoryPolicy
.specific(categories)
store.shield.webDomainCategories = ShieldSettings
.ActivityCategoryPolicy
.specific(categories)
}
if let webDomains = activitySelection.webDomains.isEmpty ? nil : activitySelection.webDomainTokens {
store.shield.webDomains = webDomains
}
} catch {
print("Error starting monitoring: \(error)")
}
}
func stopBlock() {
store.shield.applications = nil
store.shield.webDomains = nil
store.shield.applicationCategories = nil
store.shield.webDomainCategories = nil
center.stopMonitoring([activityName])
}
}
Currently, this AppBlockManager is part of the main app target, not within the DeviceActivityMonitor extension, which is currently empty. With this configuration, I can only have one blocking session active at a time, and when it is deactivated, all restrictions are removed. I tried using different ManagedSettingsStore instances, each named individually, but without success.
2. Problems with scheduling restrictions:
Currently, when setting up scheduled monitoring via DeviceActivitySchedule, the restrictions are activated immediately, ignoring the specific times scheduled (e.g. starting at 2pm and ending at 5pm). I need the schedule to work correctly, applying the restrictions only during the defined periods.
Alternatively, I've considered running a background task that checks whether active sessions (up to a maximum of 3) should apply the restrictions at that time, but I'm still looking for a more suitable solution.
In view of these challenges, I would like some guidance on the following points:
What would be the best way to configure the DeviceActivityMonitor extension to receive and apply different FamilyActivitySelections, ensuring that the blocking sessions are independent and can run simultaneously?
Is there a recommended approach to ensure that restrictions scheduled via DeviceActivitySchedule are applied and removed according to the times and days defined by the user, ensuring that applications are restricted only during the scheduled periods?
Topic:
App & System Services
SubTopic:
General
Tags:
Device Activity
Managed Settings
Family Controls
Screen Time
Why is my screen time doing this??? I’ve literally been on my phone about 30 mins today but it’s saying I’ve been on it all night. but it’s all grey lines and I can’t look at what it is?
Hello
I updated my iPhone 13 to iOS 18 a few days ago and the last two nights, it indicated that my screen was on whilst I had actually switched my phone off for the night.
Last night I made sure to close all apps before I switched it off but Screen Time still says that my screen was on.
Is there a way to fix this so as to have screen time that actually corresponds to my screen time?
I’ve seen other users experiencing the same problem but haven’t found a solution.
Thanks!
Hi, I noticed that all my apps are sometimes blocked even if I don’t have set up screen time for them. How can I fix it?
I use a parental control app and it should block apps only if I enable child mode, but after the iOS 18 update, it blocks apps even when I am still in parent mode.
Tl:dr What are some reasons my bundleIDs aren't showing up and does anyone have good resources to setup the screentime API/DeviceActivityMonitorExtension?
I'm working on an iOS app that uses the FamilyControls and DeviceActivity frameworks to monitor and restrict app usage. The app allows users to select apps and set usage limits. When a limit is reached, a DeviceActivityMonitorExtension should block the selected apps.
My App setup: Have a model that is called when users select apps to manage these app bundle IDs are then serialized and sent to the Device Monitor Extension via App Group so it can be used when the event threshold is reached. Cant use Application Tokens because they are not serielizable and cant be passed to the extension.
Problem: While testing, I’m unable to retrieve the bundleIdentifier and localizedDisplayName from the Application objects after selecting apps. Instead, these properties are nil or empty, preventing me from saving the bundle IDs to share with the extension via App Groups.
Assumptions: I suspect this issue is due to missing the com.apple.developer.screentime.api entitlement, which might be required to access these properties even during development. I've requested for the entitlement but its still under review.
Key Code Snippets:
Authorization Request:
class ScreenTimeManager: ObservableObject {
static let shared = ScreenTimeManager()
@Published var isAuthorized: Bool = false
func requestAuthorization() async {
do {
try await AuthorizationCenter.shared.requestAuthorization(for: .individual)
DispatchQueue.main.async {
self.isAuthorized = AuthorizationCenter.shared.authorizationStatus == .approved
print("Authorization status: \(AuthorizationCenter.shared.authorizationStatus)")
}
} catch {
DispatchQueue.main.async {
print("Authorization failed: \(error.localizedDescription)")
self.isAuthorized = false
}
}
}
}
Accessing bundleIdentifier:
print("addAppGroup() Called")
let managedApps = selection.applications.compactMap { application -> ManagedApp? in
guard let token = application.token else {
print("No token for application: \(application)")
return nil
}
let app = Application(token: token)
print("New Application instance: \(app)")
guard let bundleID = app.bundleIdentifier, !bundleID.isEmpty else {
print("Bundle identifier is empty or nil for application: \(app)")
return nil
}
let displayName = app.localizedName ?? "Unknown App"
print("Processing application with bundleIdentifier: '\(bundleID)' and displayName: '\(displayName)'")
return ManagedApp(
bundleIdentifier: bundleID,
applicationToken: token,
localizedDisplayName: displayName
)
}
if managedApps.isEmpty {
print("No managed apps created. Exiting addAppGroup().")
return
}
// Continue with creating DeviceActivityEvent...
}
Logs - Shows application token but never bundleID or LocalizedDisplayname
Application(bundleIdentifer: nil, token: Optional(128 byte <TOKEN_PRESENT>), localizedDisplayName: nil)
What I've Tried:
Ensured Screen Time is enabled on the device.
Verified App Group configuration in both app and extension.
Checked that authorization is being requested and the status is .approved.
Cleaned and rebuilt the project.
Questions:
Is the com.apple.developer.screentime.api entitlement required to access bundleIdentifier and localizedDisplayName when using .individual authorization?
Is there a way to access these properties without the entitlement, or am I missing a configuration step?
Has anyone faced a similar issue and found a solution?
Lastly, is there a good place for additional resources on the screentime API??
I implemented parents to manage their children's apps with FamilyActivityPicker.
Then, is there way to get child’s app list without FamilyActivityPicker?
Hi everyone,
I’m encountering an issue with shield.applicationCategories = .all(except: applications.applicationTokens) when trying to shield all apps except a specified few. Despite using this configuration, all apps are getting shielded, including those that should be exempt.
I’ve verified that the correct applicationTokens are being used and ensured that there are no conflicting schedules that might override this configuration. Interestingly, the ShieldConfiguration appears for the apps that are supposed to be blocked, but not for the ones in the exception list.
Has anyone else experienced this issue, or does anyone have insights into what might be causing this behavior?
Thanks in advance!
Topic:
App & System Services
SubTopic:
General
Tags:
Device Activity
Managed Settings
Family Controls
Screen Time
Made a screen time password a little while ago and recently updated to ios 18. Went to turn it off and couldn’t remember the password. There was not forgot password option and now I’m on my like millionth attempt to guess the password.
Hi everyone,
I'm working on a Swift application and trying to determine whether an application has exceeded its limit based on an ApplicationToken. I have the following function to check if the current app's token matches any of the tokens stored when the app limit is reached:
private func isAppLimitExceeded(for application: Application?) -> Bool {
guard let application = application, let appToken = application.token else { return false }
let exceededTokens = configManager.getAppLimitExceededTokens()
return exceededTokens.contains { exceededToken in
appToken == exceededToken
}
}
The function configManager.getAppLimitExceededTokens() returns a list of [ApplicationToken] that were saved in UserDefaults when an app limit is reached. The goal is to use the isAppLimitExceeded method to verify if the current shield for the app is triggered due to a limit/threshold being exceeded.
This function is part of a class that conforms to the ShieldConfigurationDataSource protocol:
class ShieldConfigurationExtension: ShieldConfigurationDataSource {
// ...
}
My concern is whether comparing two ApplicationToken instances using == is a reliable method for determining if they are equal.
Are ApplicationToken objects guaranteed to be comparable with == out of the box, or do I need to implement Equatable or another method of comparison?
Could there be issues with tokens stored in UserDefaults not matching due to reference or serialization differences?
Any guidance on how to ensure proper comparison of these tokens would be appreciated!
Thanks!
Hi there,
I'm currently working with the Screen Time API using the family controls package to manage application usage on iOS devices. I want to block access to all applications except those specifically allowed by the user. While the ManagedSettingsStore.shield.applications method works for defining apps to block. However, integrating the .all(except:) from ShieldSettings.ActivityCategoryPolicy.all(except:) is unfortunately not working for me.
Here is my code snippit. Can anyone help out? And if anyone has examples of similar implementations or tips on best practices for using the Screen Time API for such scenarios, please let me know!
class ShieldManager: NSObject, ObservableObject, NFCNDEFReaderSessionDelegate {
@Published var discouragedSelections = FamilyActivitySelection()
private let store = ManagedSettingsStore()
func shieldActivities() {
// Clear to reset previous settings
store.clearAllSettings()
// This is an array with the app and category selection
let applications = discouragedSelections.applicationTokens
let categories = discouragedSelections.categoryTokens
//
//https://developer.apple.com/documentation/managedsettings/shieldsettings/activitycategorypolicy
store.shield.applications = applications.isEmpty ? nil : applications
store.shield.applicationCategories = categories.isEmpty ? nil : .specific(categories)
store.shield.webDomainCategories = categories.isEmpty ? nil : .specific(categories)
}
f