Device Activity

RSS for tag

Monitor web and app usage through custom time windows and events.

Posts under Device Activity tag

96 Posts
Sort by:
Post marked as solved
4 Replies
2.5k Views
Hi folks! Please help me to clarify some things related to Screen Time API. What the keys differences between individual and child authorization? With individual type of auth user can do sign-out from iCloud and delete the app. What else differentiate this type of users? Can we use DeviceActivityEvent for remote control with individual auth? Can the parental or guardian see/get the statistic of apps usage? Is the individual auth available to all users or just those who are in the Apple's family? I'll really appreciate any help and answer! Thank you in advance!
Post marked as solved
3 Replies
2.8k Views
Hi all! I'm thankful to Kmart for his answers related to Screen Time API features iOS 15 / iOS 16. That really helpful! Please, help me to clarify a few more things... As I read here in the comment ManagedSettings has two type of restrictions, shielding and blocking. Is blocking type of restriction available for users with individual type of auth? If the answer on the first question is "No", does that mean that individual user will be able just to skip the shielding screen and continue to use apps? If individual user can skip shielding, will it be allowed to do it with a passcode or without, if the passcode wasn't set for Screen Time in the phone settings? I'll really appreciate any help and answer! Thank you in advance!
Post not yet marked as solved
7 Replies
2.2k Views
When I tap on one of the buttons in the ShieldAction extension I want to close the shield and open the parent app instead of the shielded app. Is there any way of doing this using the Screen Time API? class ShieldActionExtension: ShieldActionDelegate {      override func handle(action: ShieldAction, for application: ApplicationToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {     // Handle the action as needed.           let store = ManagedSettingsStore()               switch action {     case .primaryButtonPressed:       //TODO - open parent app       completionHandler(.defer)     case .secondaryButtonPressed:       //remove shield       store.shield.applications?.remove(application)       completionHandler(.defer)         @unknown default:       fatalError()     }   }   }
Posted
by
Post marked as solved
6 Replies
2.6k Views
Hi there! Please help me coupe with next issue... The project was building and archived without any issue. When I added Family Control capability, I started receiving this issue: I set up all certificates, created provisions. Tried to do it automatically through Xcode, did it manually, created .certSigningRequest, changed Xcode to 13 version (I'm using 14) - nothing helped me. Please share your thoughts what can be wrong? I'm not owner of Apple's dev account. I have Admin access rights. Do I need something else? Is Apple requires additional permissions or some requests to use Family Control capability? Thank you in advance! missing com.apple.developer.family-controls / Missing Family Controls from provisioning profile
Post not yet marked as solved
4 Replies
1.6k Views
I've followed along with the Screen Time API demos (https://developer.apple.com/videos/play/wwdc2021/10123/) Also followed along with this guide, which is essentially the same: https://www.folio3.com/mobile/blog/screentime-api-ios/ I'm able to restrict access to apps/categories with the FamilyActivityPicker and FamilyActivitySelection. I can set a DeviceActivitySchedule, and then use DeviceActivityCenter to start monitoring it. I can tell that the schedule is working, because MyMonitor:intervalDidStart() does get called, and it works except for the restricting of apps/categories/webCategories. It's as if MyModel does not have any values set from within MyMonitor. I've confirmed that MyModel does have the correct FamilyActivitySelection apps etc, everywhere else in my Target, before and after the MyMonitor:intervalDidStart() gets called. MyMonitor is in a separate target called MonitorExtension, that I created using the Device Activity Monitor Extension template. But I made sure to set the Target Membership of MyModel to both my main target, and my extension target. I have set NSExtensionPrincipalClass to $(PRODUCT_MODULE_NAME).MyMonitor, as suggested. I have added MyModel.swift to the Compiled Sources in my extensions Build Phases. I have edited my apps build scheme, to make sure the extension target is also built. One more interesting thing is that debugger breakpoints and print statements do not work from within my extension. I've even tried caching a string from within MyMonitor:intervalDidStart, and tried to retrieve it afterwards in my main target, but it is nil. Still, I've confirmed that intervalDidStart was actually called by adding any removing store.application.denyAppInstallation = true, and having it work correctly. I've spent so much time on this problem, any help would be massive.. Here are the files I've referenced: import UIKit import MobileCoreServices import ManagedSettings import DeviceActivity class MyMonitor: DeviceActivityMonitor {   let store = ManagedSettingsStore()   override func intervalDidStart(for activity: DeviceActivityName) {     super.intervalDidStart(for: activity)     let model = MyModel.shared     let applications = model.selectionToDiscourage.applicationTokens     let categories = model.selectionToDiscourage.categoryTokens     let webCategories = model.selectionToDiscourage.webDomainTokens          if applications.isEmpty {      print("No applications to restrict")     } else {      store.shield.applications = applications     }          if categories.isEmpty {      print("No categories to restrict")     } else {      store.shield.applicationCategories = ShieldSettings.ActivityCategoryPolicy.specific(categories, except: Set())     }          if webCategories.isEmpty {      print("No web categories to restrict")     } else {      store.shield.webDomains = webCategories     }     store.dateAndTime.requireAutomaticDateAndTime = true     store.account.lockAccounts = true     store.passcode.lockPasscode = true     store.siri.denySiri = true     store.appStore.denyInAppPurchases = true     store.appStore.maximumRating = 200     store.appStore.requirePasswordForPurchases = true     store.media.denyExplicitContent = true     store.gameCenter.denyMultiplayerGaming = true     store.media.denyMusicService = true     store.application.denyAppInstallation = true   }   override func intervalDidEnd(for activity: DeviceActivityName) {     super.intervalDidEnd(for: activity)     store.shield.applications = nil     store.shield.applicationCategories = nil     store.shield.webDomains = nil     store.dateAndTime.requireAutomaticDateAndTime = false     store.account.lockAccounts = false     store.passcode.lockPasscode = false     store.siri.denySiri = false     store.appStore.denyInAppPurchases = false     store.appStore.maximumRating = 1000     store.appStore.requirePasswordForPurchases = false     store.media.denyExplicitContent = false     store.gameCenter.denyMultiplayerGaming = false     store.media.denyMusicService = false     store.application.denyAppInstallation = false   } } import Foundation import FamilyControls import DeviceActivity import ManagedSettings class MyModel: ObservableObject {   static let shared = MyModel()   let store = ManagedSettingsStore()   private init() {}   var selectionToDiscourage = FamilyActivitySelection() {     willSet {       let applications = newValue.applicationTokens       let categories = newValue.categoryTokens       let webCategories = newValue.webDomainTokens       store.shield.applications = applications.isEmpty ? nil : applications       store.shield.applicationCategories = ShieldSettings.ActivityCategoryPolicy.specific(categories, except: Set())       store.shield.webDomains = webCategories      }   }   func initiateMonitoring(scheduleStart: DateComponents, scheduleEnd: DateComponents) {     let schedule = DeviceActivitySchedule(intervalStart: scheduleStart, intervalEnd: scheduleEnd, repeats: true, warningTime: nil)     print(scheduleStart)     print(scheduleEnd)     let center = DeviceActivityCenter()     do {       try center.startMonitoring(.daily, during: schedule)     }     catch {       print ("Could not start monitoring \(error)")     }          store.dateAndTime.requireAutomaticDateAndTime = false     store.account.lockAccounts = false     store.passcode.lockPasscode = false     store.siri.denySiri = false     store.appStore.denyInAppPurchases = false     store.appStore.maximumRating = 1000     store.appStore.requirePasswordForPurchases = false     store.media.denyExplicitContent = false     store.gameCenter.denyMultiplayerGaming = false     store.media.denyMusicService = false     store.application.denyAppInstallation = false   } } extension DeviceActivityName {   static let daily = Self("daily") } import SwiftUI import FamilyControls struct AppPicker: View {   @StateObject var model = MyModel.shared   @State var isPresented = false       var body: some View {     Button("Select Apps to Discourage") {       isPresented = true     }     .familyActivityPicker(isPresented: $isPresented, selection: $model.selectionToDiscourage)   } }
Posted
by
Post not yet marked as solved
2 Replies
852 Views
I am using the DeviceActivity framework to let the user track their activity (so also for non FamilySharing users). For tracking to cover multiple devices, does the app need to be installed/running on all devices or can the OS report activity to the app on one device? I haven't found a way to do that...
Posted
by
cmj
Post marked as solved
2 Replies
1.1k Views
There is frequently a delay of a few seconds before a DeviceActivityReport renders its view generated from the DeviceActivityReportExtension. It will also sometimes flash with zero data before hydrating with the real activity data (tested with extension code taken directly from XCode boilerplate) Is there a way to be notified when the DeviceActivityReport renders successfully or is still processing, i.e. so a loading indicator can be presented while the extension runs? Thanks!
Posted
by
Post not yet marked as solved
4 Replies
2k Views
I am trying to build an app that blocks access to other apps (Like screentime) through react native. I know that IOS has ScreenTime API which has device activity which has the feather to do that. Is it possible to integrate this into a react native app? I've been looking online but can't find much information or documentation regarding this, but I failed to find much.
Posted
by
Post not yet marked as solved
2 Replies
733 Views
currently when I try to set several schedules to the same activity the latest schedule I set is the only one I understand I can have only 1 schedule for activity. ? I thought about setting a new schedule on the intervalDidEnd but, I get no interval did start if the current time is in the middle of the interval I set For example, now it is 15:00, and my previous interval started at 14:00 and ends at 16:00 but the user sets a new interval from 14:30 - 16:40 I call the deviceActivityCenter.stopMonitoring([someActivityName]) and get noIntervalDidEnd event Then I set the new interval successfully with deviceActivityCenter.startMonitoring(someActivityName, during: deviceActivitySchedule) and get no intervalDidStartEvent So how can I achieve several intervals? If I had gotten the events of the start and end it would be possible Thanks for the help
Posted
by
Post not yet marked as solved
3 Replies
851 Views
Hi there, In rare cases (about 0.2% of the time?), I'm seeing calls to startMonitoring on an instance of DeviceActivityCenter throw an error with localizedDescription "couldn’t communicate with a helper application." I am certain I am passing valid parameters to the startMonitoring call because sometimes a naive retry after a few seconds succeeds. Similarly, I am certain that FamilyControls permissions have been granted by the user. Was hoping to get more color from the systems team on what some causes of this error are and if it is avoidable by the programmer.
Posted
by
Post not yet marked as solved
5 Replies
1.5k Views
Hi, I'm trying to make use of the Device Activity Labels where you supply an ApplicationToken. I can successfully get it to show the icon + title of the Application (twitter in my case) but I cannot get the styling to work. // Works .labelStyle(.iconOnly) .labelStyle(.titleOnly) .border(...) ![]("https://developer.apple.com/forums/content/attachment/9660b578-a36f-4d5a-ae18-653a207aa5ab" "title=Screenshot 2023-03-12 at 12.57.34 PM.png;width=1218;height=844") // Does NOT work .font(.largeTitle) .foregroundColor(.blue) I have checked the same style (or just modifiers) against a standard Label and they actually do work in the code below. // This is an application token. Some style not applied. Label(targetApp) .labelStyle(MyStyle()) // Showing the same style using a simple label. All styles correctly applied. Label("Twitter", systemImage: "video.square.fill") .labelStyle(MyStyle()) Is changing the font + color of the title for this Label(_ applicationToken:) supported?
Posted
by
Post not yet marked as solved
7 Replies
1.9k Views
Every time I present an application title using SwiftUI view using Label(some_token) I get 3x of these logs, which sometimes incurs a noticeable lag in displaying my containing view. Otherwise the icon + title display correctly. I have tried making the most simple SwiftUI View just containing Label(some_token) without any other code, no state, no navigation, no transitions, no other views, just that and I still get this - usually in triplicate: [activityItem] Label is already or no longer part of the view hierarchy [activityItem] Label is already or no longer part of the view hierarchy [activityItem] Label is already or no longer part of the view hierarchy If I use .labelStyle(.titleOnly) I only see it twice. Here's the code I used var body: some View { VStack { // uses a static token provided just for testing. // same behavior regardless of how the token is passed in. Label(some_static_token) .labelStyle(.titleOnly) } } Is this log something to be expected?
Posted
by
Post not yet marked as solved
3 Replies
1k Views
Hello, I am trying to make use of Screentime API in my app, I have issue with the DeviceActivityMonitor extension. I have schedule DeviceActivitySchedule which I set like this: let schedule = DeviceActivitySchedule( intervalStart: DateComponents(hour: 00, minute: 00), intervalEnd: DateComponents(hour: 23, minute: 59), repeats: false ) and DeviceActivityEvent which I set like this: let dateComponent = DateComponents(minute: 1) var events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [ .encouraged: DeviceActivityEvent(threshold: dateComponent) ] The issue is that every time I start monitoring, by calling this piece of code from the app: do { print("Try start monitoring...") try center.startMonitoring(.daily, during: schedule, events: events) } catch { print("Error: ", error) } I catch in the extension that the event intervalDidStart is called, but in the same second I get called eventDidReachThreshold. What could be done wrong? Is event set properly? I was trying to set event with different Datecomponents (minute, hour, second), by setting different amount of time, like: let dateComponent = DateComponents(minute: 3) let dateComponent = DateComponents(second: 120) but nothing worked differently, every time, it was triggering eventDidReachThreshold right after the interval starts. If I put something unnormally high, like: let dateComponent = DateComponents(second: 120) The event eventDidReachThreshold is not triggered same time as the intervalStarts, but it is not counting time properly. Please if someone could help me, I want to be able to use events properly, with the amount of time which I set. Any help would be appreciated. Thanks in advance
Posted
by
Post not yet marked as solved
5 Replies
1.1k Views
I understand that the DeviceActivityMonitor extension is designed to be very lightweight, and the system terminates the extension as soon as its callback functions return. However, I want to save values to UserDefaults inside the extension's callback functions. This creates concurrency issues for my app because the documentation for UserDefaults states that "When you set a default value, it’s changed synchronously within your process, and asynchronously to persistent storage and other processes." In order to guarantee that these values are persisted before the extension terminates my app, I want to call UserDefaults.synchronize(), but its documentations states that it's "unnecessary and shouldn't be used." Furthermore, it's listed under "Legacy" but not marked deprecated. Is synchronize() the recommended way to solve my concurrency problem? Or could there be a better way to wait for storage synchronization before returning from a synchronous function?
Posted
by
Post not yet marked as solved
2 Replies
898 Views
There have been several posts (i.e. here, here) about the lagginess of the DeviceActivityReport extension. Often it takes a few seconds for the view to load, or sometimes doesn't show up at all. I've confirmed this is not a case of excessive memory usage in the extension (exceeding 100MB), because I've profiled the extension and it consistently maxes out at 10MB. I've placed a loading screen behind the DeviceActivityReport inside a ZStack in the host app in order to see if the lag is because it takes some time for the extension to spin up - but the loading screen does not appear, indicating that the extension is running right away, but receiving the view from the extension in the host app is where the lag happens. It's been extremely difficult to debug because the lag only occurs a fraction of the time, and DeviceActivityReport is pretty much a black box. There's no documentation about how the host app and extension actually communicate. I've also combed through the logs using the Console app on Mac with no indication of any issues, (but I do see the message "Connection to view service was invalidated" coming from the extension even when there is no lag). I'm pretty convinced that the problem lies in the host app, because when I strip everything away from the host app, DeviceActivityReport never lags. I suspect that there are processes running (network requests, async tasks, or state updates) that block the report view from being received in the host app. Could you please help me understand why this could be happening, with as many details as you could provide? Any details on how the host and extension communicate, what processes could block the view from appearing, or anything else. Seems like this is a common issue but plenty of apps also don't experience it. Any guidance you can provide would be extremely helpful, as I've been trying to fix this bug every since I've been working with this API with no luck. Thanks in advance!
Posted
by
Post not yet marked as solved
4 Replies
954 Views
The eventDidReachThreshold calls immediately not waiting for accumulated time. Example of setting the event: let events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [ .monitorEducation: DeviceActivityEvent( applications: educationalApps.applicationTokens, threshold: DateComponents(minute: 15) ) ] What could be wrong?
Post not yet marked as solved
5 Replies
1.3k Views
Hi, I'm having trouble understanding what is the correct DateComponents format for the DeviceActivityCenter.startMonitoring to work as expected. Here's how it behaves with my setup: The schedule interval is set for 15 minutes (the minimum). On intervalDidStart I set the shields shield.applicationCategories = .all(except: exclCat) shield.webDomainCategories = .all(except: exclWeb) On intervalDidEnd I clear the settings shield.applicationCategories = nil shield.webDomainCategories = nil Different behavior with different DeviceActivitySchedule intervals. In the below examples I'll refer to hour, minute and second components as time components, and the calendar, timeZone, year, month, day, hour, minute and second components as date and time components. Also, with all combinations below no errors are thrown when calling the startMonitoring method. A. ❌ The start interval has time components, while the end interval has date and time components: The intervalDidStart is not triggered. DeviceActivitySchedule(schedule: <USDeviceActivitySchedule: 0x28354a5e0> IntervalStart: <NSDateComponents: 0x2839c7f40> { Hour: 9 Minute: 24 Second: 55 IntervalEnd: <NSDateComponents: 0x2839c7f70> { Calendar: <CFCalendar 0x2818f9090 [0x1e4fb1d10]>{identifier = 'gregorian'} TimeZone: Asia/Manila (GMT+8) offset 28800 Calendar Year: 2023 Month: 5 Leap Month: 0 Day: 15 Hour: 9 Minute: 39 Second: 55 Repeats: 0 WarningTime: (null)) B. ❌ The start interval has date and time components, while the end interval has time components: Here, the opposite of the above example happens — the intervalDidStart is triggered, but the intervalDidEnd is not. C. ❌ Both intervals have time components: The intervalDidStart is not triggered. D. ✅ Only hour, minute, and second components for both start and end intervals: Callbacks are called as expected. DeviceActivitySchedule(schedule: <USDeviceActivitySchedule: 0x282e80450> IntervalStart: <NSDateComponents: 0x2822f39f0> { Hour: 9 Minute: 12 Second: 15 IntervalEnd: <NSDateComponents: 0x2822f3a00> { Hour: 9 Minute: 27 Second: 15 Repeats: 0 WarningTime: (null)) So it seems that the correct and working version is with the time components only. However, from the documentation, the maximum schedule interval is a week. So if I need to set the schedule starting from a certain time of day A and ending in a certain time of day B, what should the DateComponents look like? Thanks for you help!
Posted
by
Post not yet marked as solved
0 Replies
487 Views
If an app is installed on multiple users' devices, does the device activity framework allow the app to store the device activity data and compare it across users? For example, user A uses an app for 1 hour and user B uses the same app for 2 hours. I want to inform User B that they were on the app for 1 hour more than User A or .5 hours more than the average. is this possible?
Posted
by
Post not yet marked as solved
1 Replies
800 Views
When using ManagedSettingsStore to shield apps, no system apps are shielded even when specifying all application categories. Here is my code: managedSettings.shield.applicationCategories = .all() Even when using the FamilyActivityPicker and selecting "All Apps & Categories" system apps like Messages do not get shielded. managedSettings.shield.applicationCategories = .specific(selectedCategories) I find this strange, since Messages exists inside the Social category, and is tracked fine using DeviceActivityMonitor. Why can't it be shielded using app categories? I'd like to be able to shield all apps, including Messages, without having the user to specifically select the apps using FamilyActivityPicker. Is that possible?
Posted
by