Device Activity

RSS for tag

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

Posts under Device Activity tag

87 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Family Controls App Help
Hello! I am a relatively new Apple developer and am almost done with my first app. I am implementing the Screen Time API to my app because the app is designed to help the user digitally detox and I am trying to make it so the user can select which apps they would like to monitor from a list of their apps on their phone so I am using the family activity picker but I just can't extract the data needed to track the apps. I am wondering how to do this. Thank you!
0
0
42
1w
DeviceActivityReport inside SwiftUI Button doesn’t receive tap gestures (ScreenTime API, iOS 17+)
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.
0
0
64
3w
Screen Time API: How to map bundleIdentifier to ApplicationToken for DeviceActivityMonitor when FamilyActivitySelection.Application.bundleIdentifier is nil?
I'm using FamilyActivityPicker to get consent for app/category management, which returns a FamilyActivitySelection object. I serialize this FamilyActivitySelection object (just applicationTokens and categoryTokens) and pass it to my DeviceActivityMonitor extension via App Group UserDefaults. I am using the JSON encoder/decoder over PropertyList (though both seem to exhibit the same behavior). After inspecting the FamilyActivitySelection object immediately after it's returned by FamilyActivityPicker in the main app, the application.bundleIdentifier property is consistently nil for every Application object within selection.applications. Similarly, category.localizedDisplayName is nil for ActivityCategory objects. This happens whether "Select All Apps" is used or if apps/categories are selected individually. I understand that this is the intended behavior due to Apple's user privacy policies. I read on another post that my app can be provided with bundle identifiers and app names within Shield Configuration extensions and Device Activity Report extensions - I'm not sure which ones or how exactly to do this. I am aware that I can use Label(applicationToken) SwiftUI view to display the app name/icon, but this doesn't give programmatic access to the bundleIdentifier string. My app will not log or export these bundleIdentifiers outside of its sandbox. My goal is to create mappings to the FamilyActivitySelection with the publicly accessible bundleIdentifiers. Any guidance, examples, or clarification on the intended workflow for this scenario would be greatly appreciated!
0
0
67
3w
Recently used applications on guardian phone - FamilyControls, DeviceActivityReport
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?
1
0
50
May ’25
FamilyControls App Blocking Not Working for External TestFlight Testers
Hi everyone, I'm following up on this post I made earlier about an issue I'm having with FamilyControls and the DeviceActivityMonitor extension not working for external TestFlight testers. To briefly recap: I have official Apple approval for the com.apple.developer.family-controls entitlement (distribution) The entitlement is added to both my main app and the DeviceActivityMonitor extension The App Group is correctly configured for both targets On internal TestFlight builds, everything works as expected: app blocking works, the extension runs, and selected apps are shielded. On external TestFlight builds, users get the Screen Time permission prompt, can select apps to block, but nothing is blocked. Since that post, I submitted a Code Level Support request, and Apple asked me to file a bug report via Feedback Assistant. I did that almost a month ago. The only reply I’ve received since is that they can’t give a timeframe or guarantee it will be resolved. I'm stuck in limbo with no updates and no fix. This feature is critical to my app and I cannot launch without it. I’ve reached out to other developers who use app blocking, and none of them have run into this issue. My setup seems correct, and Apple has not said otherwise. If anyone has experienced something similar, found a workaround, or knows how to get real movement on a bug report like this, I would really appreciate any help. It’s been weeks, and I just want to launch my app. Thanks so much.
3
0
118
3w
How can I open and write to an SQLite database from my DeviceActivityReport Extension?
Hello everyone, I’m working on an iOS app that uses the new DeviceActivity framework to monitor and report user screen‐time in an extension (DeviceActivityReportExtension). I need to persist my processed screen‐time data into a standalone SQLite database inside the extension, but I’m running into issues opening and writing to the database file. Here’s what I’ve tried so far: import UIKit import DeviceActivity import SQLite3 class DeviceActivityReportExtension: DeviceActivityReportExtension { private var db: OpaquePointer? override func didReceive(_ report: DeviceActivityReport) async { // 1. Construct path in app container: let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.mycompany.myapp") let dbURL = containerURL?.appendingPathComponent("ScreenTimeReports.db") // 2. Open database: if sqlite3_open(dbURL?.path, &db) != SQLITE_OK { print("❌ Unable to open database at \(dbURL?.path ?? "unknown path")") return } defer { sqlite3_close(db) } // 3. Create table if needed: let createSQL = """ CREATE TABLE IF NOT EXISTS reports ( id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT, totalScreenTime DOUBLE ); """ if sqlite3_exec(db, createSQL, nil, nil, nil) != SQLITE_OK { print("❌ Could not create table: \(String(cString: sqlite3_errmsg(db)))") return } // 4. Insert data: let insertSQL = "INSERT INTO reports (date, totalScreenTime) VALUES (?, ?);" var stmt: OpaquePointer? if sqlite3_prepare_v2(db, insertSQL, -1, &stmt, nil) == SQLITE_OK { sqlite3_bind_text(stmt, 1, report.date.description, -1, nil) sqlite3_bind_double(stmt, 2, report.totalActivityDuration) if sqlite3_step(stmt) != SQLITE_DONE { print("❌ Insert failed: \(String(cString: sqlite3_errmsg(db)))") } } sqlite3_finalize(stmt) } } However: Path issues: The extension’s sandbox is separate from the app’s. I’m not sure if I can use the same App Group container, or if there’s a better location for an on‐extension database. Entitlements: I’ve added the App Group (group.com.mycompany.myapp) to both the main app and the extension, but the file never appears, and I still get “unable to open database” errors. My questions are: How do I correctly construct a file URL for an SQLite file in a DeviceActivityReportExtension? Is SQLite the recommended approach here, or is there a more “Apple-approved” pattern for writing data from a DeviceActivity extension? Any sample code snippets, pointers to relevant Apple documentation, or alternative approaches would be greatly appreciated!
1
0
62
May ’25
How to get the bundleIdentifier or app name from FamilyActivitySelection's applicationTokens?
I'm working with the FamilyControls and DeviceActivity frameworks in iOS (Swift). In my app, I collect selected apps using a FamilyActivitySelection, and I access the selected apps via selection.applicationTokens, which gives me a Set. I would like to get either the bundle identifier or the display name of the selected apps from these ApplicationTokens. I tried creating an Application instance using: let app = Application(token: token) print(app.bundleIdentifier) print(app.localizedDisplayName) However, both bundleIdentifier and localizedDisplayName are always nil. My questions are: Outside the extension (in the main app), how can I get the bundleIdentifier or display name from an ApplicationToken? Is there an Apple-recommended way to resolve a Token into something human-readable or usable? If not, what is the best practice to store or identify user-selected apps for later use? Environment: iOS 17, Swift 5, Using FamilyControls and DeviceActivity APIs. Thank you for any help!
2
0
60
Apr ’25
Device Activity Report Not showing any information
All After about 20 hours straight of working on this and having scrapped it twice I am realizing I should have asked everyone here for help. I am just trying to get device activity report extension to work inside an existing app. I have been heavily using family controls, managedsettings and deviceactivity and decided it would be nice to output some of the app usage so the User (parent) can see their children's app usage. I installed the target via xcode, confirmed group names match, and think I have it embedded correctly but when I run the app and call the view within the extension to show minutes used by any apps it just shows no time has been used. In addition, when I put print statements into the extension they do not show up in console. I have confirmed the main app target->Build phases->Link binary with Libraries has: ManagedSettings.framework FamilyControls.Framework DeviceActivity.framework I have confirmed in xcode that the main app target->Build phases -> Embed Foundation Extensions has: ShieldConfiguration.appex ShieldActionExtension.appex DeviceActivityMonitor.appex I have confirmed in xcode that the main app target->Build phases-> Embed ExtensionKit Extensions has: UsageReportExtension.appex I have used the apps I am trying to show data for extensively in the last 36 hours. Here is my UsageReportExtension info.plist EXAppExtensionAttributes EXExtensionPointIdentifier com.apple.deviceactivityui.report-extension .entitlement com.apple.developer.family-controls com.apple.security.application-groups group.com.jrp.EarnYourTurnMVP2.data Here is the file in the app (timebankview.swift) calling the extension/showing the extension view(AppUsageReportView.swift) import DeviceActivity import ManagedSettings struct TimeBankView: View { @EnvironmentObject private var appState: AppState @State private var reportInterval: DateInterval = { let calendar = Calendar.current let now = Date() let yesterdayDate = calendar.date(byAdding: .day, value: -1, to: now) ?? now return DateInterval(start: yesterdayDate, end: now) }() private var reportFilter: DeviceActivityFilter { let selection = appState.screenTimeController.currentSelection return DeviceActivityFilter( segment: .daily(during: reportInterval), users: .children, devices: .all, applications: selection.applicationTokens, categories: selection.categoryTokens // webDomains: selection.webDomains // Add if needed ) } var body: some View { ZStack { Color.appTheme.background(for: appState.isParentMode) .edgesIgnoringSafeArea(.all) ScrollView { VStack(spacing: 20) { Text("Time Bank") DeviceActivityReport(.childUsageSummary, filter: reportFilter) Here is AppUsageReportView.swift import SwiftUI struct AppUsageReportView: View { let config: DetailedAppUsageConfiguration // Use the detailed config var body: some View { VStack { Text("App Usage Details") Text("Total Screen Time: \(config.totalDurationFormatted)") if config.applicationsUsed.isEmpty { Text("No specific app usage data available for the selected period/filter.") } else { Text("Apps Used:") List { ForEach(config.applicationsUsed) { appInfo in HStack { Image(systemName: "app.dashed") Text(appInfo.appName) .lineLimit(1) Text(appInfo.durationFormatted) Here is AppUsageReportScene.swift: import SwiftUI import ManagedSettings struct AppInfo: Identifiable, Hashable { let id = UUID() let appName: String let durationFormatted: String } struct DetailedAppUsageConfiguration { var totalDurationFormatted: String = "Calculating..." var applicationsUsed: [AppInfo] = [] } struct AppUsageReportScene: DeviceActivityReportScene { let context: DeviceActivityReport.Context = .childUsageSummary let content: (DetailedAppUsageConfiguration) -> AppUsageReportView func makeConfiguration(representing data: DeviceActivityResults<DeviceActivityData>) async -> DetailedAppUsageConfiguration { var config = DetailedAppUsageConfiguration() var appDurations: [String: TimeInterval] = [:] var totalAggregatedDuration: TimeInterval = 0 let formatter = DateComponentsFormatter() formatter.allowedUnits = [.hour, .minute, .second] formatter.unitsStyle = .abbreviated formatter.zeroFormattingBehavior = .pad var segmentCount = 0 var categoryCount = 0 var appCount = 0 for await activityData in data { // Check segments var tempSegmentCount = 0 for await segment in activityData.activitySegments { segmentCount += 1 tempSegmentCount += 1 totalAggregatedDuration += segment.totalActivityDuration var tempCategoryCount = 0 for await categoryActivity in segment.categories { categoryCount += 1 tempCategoryCount += 1 var tempAppCount = 0 for await appActivity in categoryActivity.applications { appCount += 1 tempAppCount += 1 let appName = appActivity.application.localizedDisplayName ?? "Unknown App" let duration = appActivity.totalActivityDuration appDurations[appName, default: 0] += duration }}} } config.totalDurationFormatted = formatter.string(from: totalAggregatedDuration) ?? "N/A" config.applicationsUsed = appDurations .filter { $0.value >= 1 .map { AppInfo(appName: $0.key, durationFormatted: formatter.string(from: $0.value) ?? "-") } .sorted { lhs, rhs in let durationLHS = appDurations[lhs.appName] ?? 0 let durationRHS = appDurations[rhs.appName] ?? 0 return durationLHS > durationRHS } if !config.applicationsUsed.isEmpty { for (index, app) in config.applicationsUsed.enumerated() { } } else { } return config }} UsageReportExtension.swift struct UsageReportExtension: DeviceActivityReportExtension { init() { print("🚀 [UsageReportExtension] Extension initialized at \(Date())") print("🔍 [UsageReportExtension] Process info: \(ProcessInfo.processInfo.processName) PID: \(ProcessInfo.processInfo.processIdentifier)") } var body: some DeviceActivityReportScene { let _ = print("📊 [UsageReportExtension] Building report scenes at \(Date())") TotalActivityReport { totalActivity in print("🕰️ [TotalActivityReport] Creating view with data: \(totalActivity)") return TotalActivityView(totalActivity: totalActivity) }}}
3
0
183
Apr ’25
iOS 18.4 (?) FamilyActivityPicker regression: presenting SFSafariViewController on top bugs
If I present "SFSafariViewController" when a "FamilyActivityPicker" is visible, it will automatically dismiss the "SFSafariViewController" and crash the "FamilyActivityPicker." I'm assuming the cause of the bug is that each is in a separate process (aside from the app), and there's some hacks to try to stop "FamilyActivityPicker" from crashing, and this is causing the new bug because "SFSafariViewController" is also in a separate process. (I'm not 100% if its just in 18.4 or iOS 18 overall...) (I'll try to file a feedback soon, but its 100% reproducible for me across multiple devices on iOS 18.4)
6
0
106
Apr ’25
Device Activity Monitor Schedules Disappear
Hey everyone, I have an app using the screen time api, I've had quite a few reports from users saying that our monitoring features stop working until they open our app. What happens is that activities and schedules set with the device activity monitor seem to disappear. This is something we check on app re-opens and so we schedule them again and that is why the monitoring starts working again. Of course our current solution is not optimal since our app is mainly passive. Has anyone experienced these kinds of issue ?
0
1
77
Mar ’25
FamilyControls Framework info.plist missing
We are trying to create a screentime app using the Family Controls as well as Device activity frameworks. The build succeeds but while pushing to an iphone we are getting an info.plist file for deviceactivity.framework could not be found error. For reference when using the Screentime API a physical device must be used not a simulator. When we remove the device activity framework this error also occurs for the family controls framework. We have added the Family Controls(development) Capability and applied for the distribution capability. We have redownloaded xcode multiple times on the main device, deleted derived data, and redownloaded all of the iphone SDKs and the issue still persists.
0
0
194
Mar ’25
Is it work startMonitoring from DeviceActivityMonitorExtension's eventDidReachThreshold function?
I want to monitor again from the bellow function of DeviceActivityMonitorExtension. I have the function of startMonitoring like this. override func eventDidReachThreshold(_ event: DeviceActivityEvent.Name, activity: DeviceActivityName) { super.eventDidReachThreshold(event, activity: activity) startMonitoring() } public func startMonitoring() { let startTime = DateComponents(hour: 0, minute: 0, second: 0) let endTime = DateComponents(hour: 23, minute: 59, second: 59)//DateComponents(hour: 11, minute: 0, second: 0)// let schedule = DeviceActivitySchedule( intervalStart: startTime,//DateComponents(hour: 0, minute: 0, second: 0), intervalEnd: endTime, repeats: true //warningTime: DateComponents(minute:1) ) let selection: FamilyActivitySelection = savedSelection() ?? FamilyActivitySelection() let center = DeviceActivityCenter() let selections = self.savedSelection() ?? FamilyActivitySelection() let applications = selections.applicationTokens let categories = selections.categoryTokens let webCategories = selections.webDomainTokens let store = ManagedSettingsStore() store.shield.applicationCategories = ShieldSettings.ActivityCategoryPolicy.specific(categories, except: Set()) store.shield.applications = applications store.shield.webDomains = webCategories let scheduleHard = DeviceActivitySchedule( intervalStart: startTime,//DateComponents(hour: 0, minute: 0, second: 0), intervalEnd: endTime, repeats: true //warningTime: DateComponents(minute:1) ) let event = DeviceActivityEvent( applications: selection.applicationTokens, categories: selection.categoryTokens, webDomains: selection.webDomainTokens, threshold: DateComponents(minute: 0)//timeLimitToUseApp i.e for 15 mins ) do { try center.startMonitoring( .weekend, during: scheduleHard, events: [ .weekend: event, ] ) print("ScreenTime Monitoring Started") } catch let error { print(error.localizedDescription) } } Please provide us with a solution about starting monitoring from DeviceActivityMonitoringExtension's eventDidReachThreshold function or if there is any other way.
0
0
248
Mar ’25
Using Device Data for Finger Printing
Our business model is to identify Frauds using our advanced AI/ML model. However, in order to do so we need to collect many device information which seems to be ok according to https://developer.apple.com/app-store/user-privacy-and-data-use/ But it's also prohibited to generate a fingerprint, so I need more clarification here. Does it mean I can only use the data to identify that a user if either fraud or not but I cannot generate a fingerprint to identify the device? If so, I can see many SKD in the market that generates Fingerprints like https://fingerprint.com/blog/local-device-fingerprint-ios/ and https://shield.com/?
1
0
373
Mar ’25
Unblocking Apps After a Scheduled Duration in FamilyControl
I am able to block apps using FamilyControl and Shield. Unblocking is also simple—just assign nil to store.shield.applications. However, I want to unblock them even when the app is not open. Use case: Let's say the app allows users to create a session where a particular app is blocked for a specific duration. Once the session starts, the app should remain blocked, and as soon as the session time ends, it should automatically be unblocked. Please help me with this. Thank you!
0
0
348
Feb ’25
How to remotely disable or block apps on a child’s device using FamilyControls and DeviceActivity API?
After reading Apple documentation (FamilyControls, DeviceActivity, ManagedSettings, ManagedSettingsUI, ScreenTime) and testing the API, I do not find a way to get the child's device apps on the parent device in order to block them or disable them for a certain time. Is there a way of doing it? Or can it only be done locally on the child device?
2
0
409
Mar ’25