Hello, thank you for building a Screen Time API.
In my reading of of the API, it seems that all components rely on Family Controls, which require a parent to authorize on a child's device.
Will Screen Time API work in contexts where there are no children's devices? Can an individual authorize Family Controls on their own phone?
Here is a use case: Imagine a user who wants to restrict access to certain apps until they have worked out for 30 minutes a day. We would use Device Activity and Managed Settings to effectuate this app.
Post not yet marked as solved
I've created a test project in which I can successfully receive the FamilyControl authorization for the child device.
Then on the parent device(where the parent account is logged in as the iCloud account), I basically used the following test code as provided in the documentation FamilyActivityPicker
struct ExampleView: View {
@State var selection = FamilyActivitySelection()
@State var isPresented = false
var body: some View {
Button("Present FamilyActivityPicker") { isPresented = true }
.sheet(isPresented: $isPresented) {
FamilyActivityPicker(selection: $selection)
}
.onChange(of: selection) { newSelection in
let applications = selection.applications
let categories = selection.categories
let webDomains = selection.webDomains
}
}
}
I get the following error on the view :
The operation couldn't be completed. (FamilyControls.ActivityPickerRemoteViewError error 1)
For authorization errors I was able to look into the FamilyControlsError enum in the FamilyControls framework, but I can't find an enum for ActivityPickerRemoteViewError.
Any idea as to why it's failing to load?
I believe I am using the right setup in terms of the account that I am logged in to. I do have the FamilyControl capability, and I was able to successfully provide authorization for the child.
Is there any other prerequisite that needs to be done to load the FamilyActivityPicker?
Also, Do you know where I can find the error codes corresponding to ActivityPickerRemoteViewError ?
What does error 1 indicate?
I do see the following in the console logs :
2021-06-09 16:42:38.430112-0400 NN Family Control[849:38700] [lifecycle] [u 9F1F2B94-76F6-4D8F-ADE3-6D1C14EE5074:m (null)] [com.apple.FamilyControls.ActivityPickerExtension(1)] Connection to plugin interrupted while in use.
2021-06-09 16:42:38.476929-0400 NN Family Control[849:38704] [lifecycle] [u 9F1F2B94-76F6-4D8F-ADE3-6D1C14EE5074:m (null)] [com.apple.FamilyControls.ActivityPickerExtension(1)] Connection to plugin invalidated while in use.
Post not yet marked as solved
I'm getting a FamilyControlsError Code=3 when requesting authorization from a simulator signed in with a child iCloud account.
When requesting authorization from a simulator signed in with a parent iCloud account I receive the expected FamilyControlsError Code=2.
There's not a lot of info on resolving these errors, and the code is pretty simple:
func requestAuthorization() {
AuthorizationCenter.shared.requestAuthorization { result in
switch result {
case .success():
print("Sucess...")
case .failure(let error):
print("Failed... \(error)")
}
}
}
Post not yet marked as solved
Can you please make the sample code for the screen time api available?
Post not yet marked as solved
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> = [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 apply the settings inside DeviceActivityMonitorExtension?
What does the application-identifier entitlement look like?
How do I use it?
Post not yet marked as solved
I am writing an app of family controls and device settings. In the docs for DeviceActivityMonitor I read about the principal class of device activity monitor extension, so I have to implement it. But, in XCode there is no such extension. How do i create it?
Post not yet marked as solved
I am able to see the list of Applications using the Family ActivityPicker on the child but not able to see it on the parent device. I can see the list of categories but there aren't any applications on each of the categories. My expectation is to see the applications which are installed on the child device. Please correct me if that is not the expected behavior.
The family sharing is setup correctly, and on requesting authorization, it does fail to get the authorization as expected, because it's the parent account.
I do see the correct behavior on the child device. I did provide authorization and I can see the list of applications inside the picker on Beta 2.
On the parent device I see the following errors in the console :
Connection error from Optional("com.apple.ManagedSettingsAgent"): Couldn’t communicate with a helper application.
Attempts remaining: 1
Failed to fetch effective value for com.apple.ManagedSettings.effective-media-settings.changed: Couldn’t communicate with a helper application.
Failed to open usage store with error: The file “Store.plist” couldn’t be opened because there is no such file.
Any ideas?
Post not yet marked as solved
What is the NSExtensionPointIdentifier for this type of extension?
Thanks.
Post not yet marked as solved
WWDC21 session 10123 shows a screen that implies the guardian instance of your app is able to select apps on your child's device to encourage or to control. In my experience with the API so far I can't see a way to do this. The API only seems to work on the child's phone. Here are my questions:
Is there a suggested way to determine whether the app is running on a guardian device? The only way I can see is to attempt AuthorizationCenter.shared.requestAuthorization and check for an error value of .invalidAccountType. But it seems you could get that error for other reasons too.
Is there a way to present FamilyActivityPicker on the guardian device but have it show apps on the child's phone? I don't see any thing in the API for selecting a child account to access with `FamilyActivityPicker', it seems to only show the phone's user's apps (or no apps if it's the guardian's phone).
After retrieving app tokens from 'FamilyActivityPicker' is there a recommended way to present to the user in the UI? The WWDC session shows an app icon and app name (i.e. "Books" and "Solar System"), but my understanding is that info is hidden from the developer for privacy reasons. So I'm wondering if the example in the session is really feasible.
Post not yet marked as solved
I've been trying to get something to work with the Screen Time API, but almost everything related to it is completely and truly broken/unimplemented. I've tried all of this in the iOS 15 Beta 2 and 3 and Xcode 13 Beta 2 and 3.
These are just a handful of the bugs I came across:
Screen Time APIs do not work on the simulator. Calling AuthorizationCenter.shared.requestAuthorization on a simulator with a logged in child account always results in "FamilyControls.FamilyControlsError Code=3"
FamilyActivityPicker does not list installed apps on either of the guardian's or child's devices, it only lists the categories. It's not clear at this point whether FamilyActivityPicker needs to be called on the parent or the child device.
Assuming restrictions can actually be set, there is no API to allow setting up of restrictions for individual kids.
After successfully authorizing a child device via AuthorizationCenter.shared.requestAuthorization, DeviceActivityCenter.startMonitoring always results in an MonitoringError.unauthorized error.
AuthorizationCenter.requestAuthorization error in callback cannot be mapped back to FamilyControlsError because it is a plain NSError with an error code and FamilyControlsError does not expose an initialiser that takes a rawValue.
Even though an app is authorized to managed ScreenTime on a child device, the child can always just delete the app. (I would try to submit a bug with device diagnostics about this using Feedback Assistant, but to top it all off at the moment I am receiving an error in FA that says "Unable to gather diagnostics" / "A problem was encountered when trying to gather diagnostics. Try gathering diagnostics again").
There's no device activity / shield configuration or shield action extension templates in Xcode. For those wondering, I created a CallDirectory extension and then changed the NSExtensionPointIdentifier in the plist to the appropriate value. What is the appropriate value? It's not mentioned in the documentation :), so I had to dig around in the Xcode support files to find out the following identifiers:
com.apple.ManagedSettings.shield-action-service
com.apple.ManagedSettingsUI.shield-configuration-service
com.apple.deviceactivity.monitor-extension
And this leads me to my last item: the documentation which is absolutely lacking. There is no programming guide for the frameworks and the Homework app we saw developed during WWDC is not available. It's not clear how the settings from the guardian app get applied to the child app. Is there a built-in mechanism or do we need to use our own implementation to transfer those changes (via push or whatever)?
Of course I reported almost all of this via Feedback Assistant, but considering I had previous feedback for other APIs sit there untouched for years in the past, it's really frustrating and it feels like I'm just talking to myself with those bug reports.
So, did I do something wrong and completely misinterpreted the capabilities and functionality of the ScreenTime API or is it truly broken and non-functional in iOS 15 Beta 2/3?
There's absolutely no mention of these issues in the release notes so I am starting to question my sanity here.
Post not yet marked as solved
we are getting error in selection.
Post not yet marked as solved
I am facing this issue when i start monitoring
error The operation couldn’t be completed. (DeviceActivity.DeviceActivityCenter.MonitoringError error 0.)
source code
in didFinishLaunchingWithOptions
center.requestAuthorization{ result in
print(result)
switch result {
case .success():
print("success")
switch self.center.authorizationStatus {
case .approved:
print("approved")
let center = DeviceActivityCenter()
do {
try center.startMonitoring(.daily, during: self.schedule)
} catch {
print("error (error.localizedDescription)")
}
case .denied:
print("denied")
case .notDetermined:
print("not determined")
}
case .failure(let error):
print(error.localizedDescription)
}
}
Post not yet marked as solved
Several questions to some intentions behind the frameworks and specific issues with it's usage, underlined with filed Feedback Assistant reports. (see below)
Understanding of the Application class
Such class can be either instantiated with the token (which only the OS provides with the FamilyActivityPicker) or through a bundleIdentifier.
When is it intended to use the bundleIdentifier initializer?
Currently it is not possible to set a threshold limit on an application created via bundleIdentifier because the DeviceActivityEvent only accepts a Set<ApplicationToken> which a developer can not instantiate.
Family Picker
Is it intended to use this picker only on the child's device or can the parent see which apps are installed on the child's device? (FB9375607 & FB9375638)
If so, how do you imagine when a new app get's installed, does the guardian have to regularly check if a new app is installed and if so update it's settings on the child device?
How can an app obtain the app icon of such an application or category? (FB9375449)
ShieldConfiguration & Action
When a schedule's callback happens (FB9375294) and an application is shielded we receive the localizedDisplayName of such application to show it in the shield UI.
In the WWDC session it was said that you could have an action that let's you do a network request to e.g. ask the guardian to lift the restriction which is located in a different extension.
Will the localizedDisplayName be available to be included in the request so that the guardian knows which app they lift the restriction on?
Filed Feedback Assistant Tickets:
Start monitoring returns Unauthorized when the device is authorized - FB9375294
Provide an app icon for an application instance - FB9375449
FamilyActivityPicker does not list apps on authorized child device - FB9375607
Show installed apps from child on guardians phone - FB9375638
Post not yet marked as solved
We would like to use this framework to enable user to customize only relevant apps or websites that will be automatically connected via VPN.
Could we use this framework for this use-case without being parental control app ?
Post not yet marked as solved
Could we detect the Lock/Unlock and Screen State Using Screen Time API.
In the Screen Time API when we shield the discourage application. At that time you are using State object MyModal(). Where we can find that MyModal Class.
Post not yet marked as solved
Hi all, I have a sample app which I created in my local development env. I added the Family Controls capability and the simulator is logged-in to a child account on iCloud that is part of a family group. When I request authorization I keep getting Error Domain=FamilyControls.FamilyControlsError Code=3 "(null)" in the error object returned with the failure result. I am thinking Code 3 represents the enum case for FamilyControlsError which would be invalidArgument. What does that mean and how do I fix it? Also is there a way to map the error object into an FamilyControlsError rather than guess which enum case it is?
Here is my code:
import SwiftUI
import FamilyControls
@main
struct TestScreentimeAPIApp: App {
@UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
if #available(iOS 15.0, *) {
let center = AuthorizationCenter.shared
center.requestAuthorization { result in
switch result {
case .success():
break
case .failure(let error):
print("error for screentime is \(error)")
}
}
}
}
Post not yet marked as solved
Hi! There weren't any mentions in the video and documentation on how the Screen Time API handles multiple children and multiple devices. Specifically, cases like this:
Multiple children with one device per child
Multiple children with multiple devices per child (e.g. iPhone + iPad)
Parent/guardian with multiple devices
The FamilyActivityPicker doesn't take any parameters. What will happen when a parent with multiple kids opens the picker?
Thanks.
Post not yet marked as solved
I want to get the length of time users are logged into to their macOS account. Is this possible using the Screen Time API?
Post not yet marked as solved
Hello!
There was mentioned in the WWDC session that
Also, on-device web content filters built with the Network Extensions framework can be included in your app and will be installed automatically and cannot be removed.
But there is a notice in documentation for Content Filter Providers that
You can use content filter providers in apps ... on iOS supervised devices only
Can we rely on the fact that the documentation is not updated yet and com.apple.developer.family-controls entitlement with authorized app on child device would be enough for on-device web content filtering?
We can't prove this with ourselves while the entitlement is only for Development where Content Filter Providers are allowed for default.