Search results for

DeviceActivityMonitor

127 results found

Post

Replies

Boosts

Views

Activity

Reply to Screen Time API is completely UNRELIABLE!
Hi @Ivan018 . To check if DeviceActivityMonitor delegates work, I created a singleton class, marked the target to both Project and DeviceActivityMonitor. This way I am able to access the selected apps from family activity picker in the monitor extension. I am shielding the apps in intervalDidEnd. You can try the same in intervalDidStart override func intervalDidEnd(for activity: DeviceActivityName) { super.intervalDidEnd(for: activity) // Handle the end of the interval. /// Once interval ends restrict the app. let model = DataModel.shared let selection = model.getScheduledSelection() let applications = selection.applicationTokens store.shield.applications = applications.isEmpty ? nil : applications }
Topic: App & System Services SubTopic: General Tags:
May ’24
Screen Time API is completely UNRELIABLE!
I've been working with the Screen Time API for almost 6 months now. I found out it's completely unreliable, testing on iOS 17.4, the DeviceActivityReport is not showing, the DeviceActivityMonitor more often than not does not fire intervalDidStart. It's very frustrating. Has anyone found out a workaround? We all know there has to be something we're doing wrong, since apps like Opal and Jono does not present those types of issues. Let's please unite our forces and find a solution. How to use this API should not be a secret!
5
0
2.1k
Apr ’24
Background Safari Tab contributing to DeviceActivityMonitor usage threshold?
I am currently debugging an issue with DeviceActivityMonitor where the threshold is reached even though the target app (e.g. Instagram) is not being used actively. I noticed that the device with the unexpected behavior had the instagram.com website opened in the Safari web browser (among hundreds of other tabs). That tab was not actively used either (not in foreground, Safari app neither used). However, I was wondering if it can happen that this website is contributing towards the threshold as well even though it is in background and not used? Otherwise I cannot explain myself this strange behavior.
0
0
662
Apr ’24
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
eventDidReachThreshold triggered while target app is in background
Hello! I am using the eventDidReachThreshold callback in the DeviceActivityMonitor in order to shield a target app after the user has spend x amount of time on it (e.g. x = 5 minutes). Many times this works fine, and I can trigger my shield after the specified threshold has been met. However sometimes, when they leave the target app before the threshold has been reached, the eventDidReachThreshold callback gets called randomly while they are doing something else on their phone (e.g. using a different app, on the Home Screen, phone locked…). From my perspective this does not make sense, since they are not actively spending time on the target app, and that time should not be counted towards the target app’s threshold. And it is also very confusing for the users because they will then find a blocked target app even though they haven’t used their time budget completely. This is not related to the intervalDidStart / intervalDidEnd callbacks, because they are not correlating with the timing of when the eve
0
0
667
Mar ’24
App Shielding unexpectedly active outside of schedule
I'm using the Screen Time API to shield apps the user selects. The problem is, that the apps are always shielded, even outside of the schedule. Here is my function initiateMonitoring: func initiateMonitoring(scheduleStart: DateComponents, scheduleEnd: DateComponents) { let schedule = DeviceActivitySchedule( intervalStart: scheduleStart, intervalEnd: scheduleEnd, repeats: true ) let center = DeviceActivityCenter() do { try center.startMonitoring(.daily, during: schedule) logger.log(STARTED MONITORING) } catch { logger.log(FAILED MONITORING: (error.localizedDescription)) } } The expected result should be that the selected Apps should be blocked during the schedule the user specified, but not outside the schedule, but it is blocked 24/7. I've experimented with the DateComponents, but the issue may be somewhere else. What's maybe interesting is, I tried Logging the DeviceActivityMonitor and somehow it doesn't get called. The logging-output from initiateMonitoring is printed in the console, but for the DeviceActivityMonitor
1
0
829
Mar ’24
DeviceActivityMonitor does not trigger UI updates
There is a way to allow DeviceActivityMonitor to make UI changes? Currently I have some code in the intervalDidStart and intervalDidEnd that updates Core Data entities, and it works correctly. However, the changes are only reflected if the app is terminated and opened again. Thus, if the app is opened and one of the methods inside the DeviceActivityMonitor is being called, the UI won't be updated. PS: I am using @FetchRequest to retrieve the core data entities called BlockEntity, and I have a little circle in the UI which should indicate the status of the block: active/inactive, so it would be nice to update the color in real time when intervalDidStart or intervalDidEnd are called.
0
0
698
Mar ’24
DeviceActivityMonitor Schedule Pause
I am trying to understand how to approach 'x minute' pauses for a DeviceActivitySchedule. For instance, I would like to let the user pause for 5 minutes from an active schedule (meaning un-shielding the apps and re-applying the shield after the 5 min has passed). The only way that came to my mind was calling the following: Calling .startMonitoring to start monitoring a new event with the same apps starting .now and ending .now + 5 minutes; Calling in the intervalDidStart, store.shield.applications.subtract(apps) so that the apps are removed from the shield. Calling in the intervalDidEnd, store.shield.applications = apps so that the apps are now shielded again. The problem is that, from the Apple Developer Documentation: The minimum interval length for monitoring device activity is fifteen minutes. So the minimum pause I could offer to the user would be 15 minutes. And that tells me this approach is most likely wrong, because all other Screen Time apps, like Opal, Jomo, AppBlock offer also 5 min pause. Does an
1
0
1.4k
Feb ’24
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
DeviceActivityMonitor Extension not working
I am developing a project with the Screen Time API, and I cannot understand why the methods inside DeviceActivityMonitor extension are not being called. Some points to note: I do start by requesting authorization from the User (this is working as expected when opening the app) Both the DeviceActivityMonitor Extension and the main app are under the same App Group I have added Family Controls capability to both targets and have the developer account to use it. I start by calling center.startMonitoring() I have overridden the original methods. Yet, when startMonitoring is called, there is no action that is supposed to be taken that is being taken, and as far as I can tell, the methods aren't even being called. Here are some relevant snippets of code: // EXT class DeviceActivityMonitorExtension: DeviceActivityMonitor { override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) let store = ManagedSettingsStore(named: .daily) } override func i
5
0
1.4k
Feb ’24
How can DeviceActivityMonitor extension communicate with my main app?
At 11:37 in this video - https://developer.apple.com/videos/play/wwdc2021/10123/ - Nolan instantiates MyModel() in swiftui view file. And then at 12:02 he just uses MyModel from extension. I have the exact same code and when I try to build my project, it fails with error that MyModel() could not be found. I shared my MyModel.swift file between extension target and main app. Now it builds. However, it seems there are two separate instances of MyModel. What is proper way for DeviceActivityMonitor extension to pass data to main app? I simply want to increment counter from extension every minute and let the main app to know that. Or even better, - is there a way to use SwiftData from Device Activity Monitor extension?
1
0
914
Feb ’24
ScreenTime API: Should the app used by the parent and the child be the same for FamilyActivityPicker to work?
Note: All the devices/accounts mentioned below are part of the same Family Group/ Is it necessary for the parent-side application (that uses FamilyActivityPicker to select the list of restricted apps) to be the same as the child-side application (that will request FamilyControls permission and will implement the DeviceActivityMonitor extension), for FamilyActivityPicker to work as expected? My observation is that given the FamilyControls permission being granted on the child device, FamilyActivityPicker when used on the parent device and rendered on an app with a different bundle identifier works as expected (by populating all the apps installed on the child device) in case of iOS 16 and 17, but does not work for iOS 15 (I am testing on iOS 15.8).
0
0
477
Dec ’23
UserDefaults and @AppStorage causing DeviceActivityMonitor to crash on iOS 17
I use App Groups to share UserDefaults data between my host app and DeviceActivityMonitor extension. On iOS 17, it appears that reading @AppStorage variables are causing my DeviceActivityMonitor extension callback functions to crash. Weirdly, writing values is okay. I see this in the extension logs: Couldn't read values in CFPrefsPlistSource<0x10fe251d0> (Domain: GROUP_NAME, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd However, through searching this log message on the internet and the fact that it also appears in my host app logs without crashing, this seems to be a warning - possibly indicating an issue but also a possible red herring. But the fact remains that when I don't read UserDefaults values or variables decorated with @AppStorage in the DeviceActivityMonitor extension, everything works fine. Are UserDefaults, and spe
2
0
1.4k
Dec ’23
DeviceActivityMonitor unreliable with iOS 17 - any other ways to schedule tasks?
We have an app that uses the Screen Time APIs to block certain apps set by the user on a schedule: We use ManagedSettings to shield selected apps We use DeviceActivityMonitor to shield the apps automatically on a schedule set by the user. The shielding starts during the intervalDidStart callback function and ends during the intervalDidEnd callback function We are getting reports from the majority of our iOS 17 users that the app blocking schedules no longer work on iOS 17. We have tested this on our own iOS 17 devices and reproduced the behavior. But the feature still works consistently on iOS 16 devices. The app is still built using Xcode 14 instead of Xcode 15 due to another issue - the DeviceActivityReport is blank for all iOS 16 users when built in Xcode 15 (link to issue on the developer forums: https://developer.apple.com/forums/thread/735915). When testing with Xcode 15 builds, the bug appears to improve - however it still occurs intermittently. Are there any other mechanisms to run tasks on r
2
0
1.2k
Dec ’23