Search results for

DeviceActivityMonitor

127 results found

Post

Replies

Boosts

Views

Activity

DeviceActivityMonitor Extension methods not being triggered at IOS16, but its work at IOS17
I'm writing an app that uses Family Control. Most of the functionality has already been debugged, including in the call try deviceActivityCenter.startMonitoring(activityName, during: schedule, events: [ eventName: event ]) Works fine on my IOS17 device, but on my old IOS16 device I found that it can't be called, like intervalDidStart, intervalDidEnd, eventDidReachThreshold etc can't be called. I checked some information, https://forums.developer.apple.com/forums/thread/724243 delete the Build Settings mentioned in this link, and change the ios Deployment Target to ios16, and found that it didn't work. Don't know where the problem is?
0
0
423
Feb ’24
Reply to Can we send Local Push Notifications from DeviceActivityMonitor extension?
Do you have an example of using App Group to share data? My DeviceActivityMonitor extension is firing the intervalDidStart(), but the categoryTokens in stored in the shared model are empty when it fires. However, when I run it using a button action in the foreground, the categoryTokens are founded and successfully shielded. I tried adding App Group capability to the main app target, and the DeviceActivityMonitorExtension target. Any insight would be appreciated.
Mar ’23
Reply to Background shield application reliability
Hi there! I am having a similar problem too. I use DeviceActivityMonitor to set 15 minute sessions for removing apps' shield. After 15-minute session is done, shield doesn't apply reliably in my internal testers. It applies if the tester is in my app or in blocked app but it doesn't if user's phone is locked or they are using another app. Although in my device it applies successfully when I build it from Xcode. This made me think whether this is a provisioning/build issue or a reliability issue (of device activity extension).
Topic: App & System Services SubTopic: General Tags:
Nov ’25
Reply to Device Activity Monitor Extension Sometimes Fails To Launch
Same here. Because DeviceActivityMonitor is generally flakey, we emit an event when intervalDidStart isn't called (as determined by intervalDidStart flipping a bit that lives in a UserDefaults container shared with the main app) Here is a graph of those events, broken down by iOS version on which they occurred. It is an iOS 17 problem. Contrast that with all app events, broken down by iOS version and which they occurred. iOS 17.4 is way overrepresented in the first, iOS 16.x is way underrepresented.
Topic: App & System Services SubTopic: General Tags:
Apr ’24
Reply to Making Network Requests from DeviceActivityMonitor Extension
DeviceActivityMonitor extensions are intended to be very lightweight and their lifecycle ends as soon as the synchronous methods you override return. In other words, your extension will likely exit before a long-running asynchronous background task (like a network request) has the chance to finish. Please file an enhancement request to add support for asynchronous callbacks. As a workaround, you can try using a locking mechanism or a DispatchGroup to force the system to wait on your network request: let waitForMyNetworkRequest = DispatchGroup() waitForMyNetworkRequest.enter() performMyAsyncNetworkRequest { // Talk to your server. // ... // Once you are done, signal the dispatch group. waitForMyNetworkRequest.leave() } // Force the system to wait 3 seconds for your network request. waitForMyNetworkRequest.wait(timeout: 3.0)
Topic: Privacy & Security SubTopic: General Tags:
Feb ’23
Reply to Device Activity Extension not being called
Update with code. I have added the following code extension DeviceActivityName{ static let daily = Self(daily) } Run the following line after authorization `let schedule = DeviceActivitySchedule( intervalStart: DateComponents(hour: 0, minute: 0), intervalEnd: DateComponents(hour: 23, minute: 59), repeats: true ) let center = DeviceActivityCenter() do{ try center.startMonitoring(.daily, during: schedule) } catch { print(error: (error)) }` And In My Class overriding DeviceActivityMonitor: override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) let applicationTokens = model.selectionToDiscourage.applicationTokens let categoryTokens = model.selectionToDiscourage.categoryTokens model.store.shield.applications = applicationTokens.isEmpty ? nil : applicationTokens model.store.shield.applicationCategories = ShieldSettings.ActivityCategoryPolicy.specific(categoryTokens) } where model is my model class for storing the selections
Topic: App & System Services SubTopic: General Tags:
May ’22
Reply to Screen Time discrepancy between DeviceActivityMonitor and DeviceActivityReport
Thank you for your reply, and for all your replies on my questions on the DeviceActivity Framework! I've filed https://feedbackassistant.apple.com/feedback/11901286. But do you have any information about apps or websites that do not fall under a specific category, but are still monitored by DeviceActivityMonitor by default (without selecting any categories, apps, or websites). I am particularly suspicious of FaceTime, which does not show up anywhere in a breakdown inside iOS' native Screen Time app, but does add to total Screen Time reported. Settings and Safari also appear to have non-typical behavior like this. Can you provide any knowledge you have about these apps that do not appear under a specific category, and how they behave under the DeviceActivity Framework?
Topic: Privacy & Security SubTopic: General Tags:
Dec ’22
Reply to Best way to pause DeviceActivitySchedule
I finally found a suitable solution, though it may not be the best approach. I'm storing the selection in shared UserDefaults with the Schedule ID as the key. This way, I can always retrieve the selected apps when I have the Schedule ID. This solved the problem of not having access to the apps that should be restricted. The other issue is actually pausing the monitoring, for which this solution is quite elegant: When the pausing action starts, all restrictions for this activity should be cleared, and the activity should no longer be monitored. Start a new activity with the identifier pause+(oldID) using the same selection and schedule times. The new schedule should contain a proper warningTime. Learn more about it here (it's not as simple as you might think): Apple Developer Documentation. In your DeviceActivityMonitor, your intervalDidStart(for activity:) function will now be called. But since the new schedule is started with the ID pause+(oldID), you can react to the name of the activity. You can n
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’24
Reply to Issues in rendering DeviceActivityController
I can't get anything to print in the functions of my class with the override functions for DeviceActivityMonitor How are you printing in those functions? If you are just using the print function in your extension, those messages will not appear in Xcode's console while you are running your app (this is because your extension is a different process than your app). In order to verify whether or not your extension is logging things, use OSLog and look for your extension's logging in the Console app on your Mac (rather than Xcode's built-in console). I can't get a rendering of a device manager - even when am just sending 0m as a string from the TotalActivityReport's makeConfiguration function without touching the data given. Apologies, but I'm not sure I understand the issue. If you discover problems with the DeviceActivity report APIs, please file a bug report using Feedback Assistant and attach a sample app that reproduces the issue. Thanks in advance!
Topic: App & System Services SubTopic: General Tags:
Feb ’23
How to designate principal class
I am building an app that uses DeviceActivity framework. Looking at the documentation, I need to subclass (https://developer.apple.com/documentation/deviceactivity/deviceactivitymonitor), I need to subclass DeviceActivityMonitor and designate the subclass as the principal class of my app extension. I am wondering how to designate my subclass as the principal class. (I am new to iOS development :) .
2
0
1.1k
Aug ’21
Reply to Is the Screen Time API completely broken in the betas?
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. The apps are now shown in the app running on the child device. They are not shown on the parent device. After successfully authorizing a child device via AuthorizationCenter.shared.requestAuthorization, DeviceActivityCenter.startMonitoring always results in an MonitoringError.unauthorized error. This appears to have been fixed. Even though an app is authorized to managed ScreenTime on a child device, the child can always just delete the app. This is fixed, parental sign-in is now required to delete the app. The DeviceActivityMonitor extension is launched at the start of the interval, so that's good as well. But there's still the critical issue where the parent app cannot list and set restricted apps installed on the child device. I'm still wondering whether the par
Topic: App & System Services SubTopic: General Tags:
Jul ’21
Reply to Extract raw Screen Time data? Security says it's 'expected'
Hi, thanks for posting this — I've been hitting the exact same wall. I'm building a screen time management app and spent considerable time trying to persist per-app usage data from the DeviceActivityReportExtension to the App Group container. I exhaustively tested every storage mechanism available: Core Data, JSON files, UserDefaults (App Group suite), Keychain, raw POSIX syscalls, SQLite, iCloud KV, and NSUbiquitousKeyValueStore. All fail with permission errors — the extension is completely write-locked at the kernel level (POSIX errno 1 / EPERM). I also confirmed the DeviceActivityMonitor extension has the same restriction. So I'm very interested in your finding that the host app can reconstruct raw activity data from the report. Could you share more about the technique you used? Specifically: How does your host app access the data from the report extension? Is it through the rendered view hierarchy, some callback mechanism, or something else entirely? Are you able to get per-app bundle identifiers
Topic: App & System Services SubTopic: General Tags:
5d
Reply to Schedule Task (Screen Time API) on iOS in background mode
Fixed by recreating Target Extension & changing from print log to show from local notification, somehow Print log from the target extension is not showing on XCode even though I already do Debug > Attach to the Process // // DeviceActivityMonitorExtension.swift // NewMonitor // // Created by Mochammad Yusuf Fachroni on 18/08/23. // import DeviceActivity import UserNotifications import ManagedSettings // Optionally override any of the functions below. // Make sure that your class name matches the NSExtensionPrincipalClass in your Info.plist. class DeviceActivityMonitorExtension: DeviceActivityMonitor { func showLocalNotification(title: String, desc: String) { let content = UNMutableNotificationContent() content.title = title content.body = desc content.sound = .default let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false) let request = UNNotificationRequest(identifier: localNotification, content: content, trigger: trigger) UNUserNotificationCenter.current().add(reques
Topic: App & System Services SubTopic: General Tags:
Aug ’23
Reply to Lock device, Restrict all apps | Screen Time API | iOS 16
Locking and unlocking the device is not possible via the Screen Time API. If you'd like to see that capability in a future release, please file a report via Feedback Assistant. You cannot restrict all apps on the device, but you can shield all app and websites by setting both store.shield.applicationCategories and store.shield.webDomainCategories to the .all() ActivityCategoryPolicy. You can also block all webContent by setting webContent.blockedByFilter to the .all() WebContentSettings.FilterPolicy. See the ShieldSettings and WebContentSettings documentation for more information. Yes you can create schedules via the Device Activity API. Here's a quick example on how to naively implement a schedule that shields all apps and websites for the weekend: In the App: extension DeviceActivityName { static let weekend = Self(weekend) } let weekendSchedule = DeviceActivitySchedule( intervalStart: DateComponents(calendar: calendar, hour: 0, minute: 0, weekday: 7), intervalEnd: DateComponents(calendar: calendar, hour: 2
Topic: App & System Services SubTopic: General Tags:
Oct ’22