Search results for

DeviceActivityMonitor

127 results found

Post

Replies

Boosts

Views

Activity

DeviceActivityCenter stops monitoring if another Screen Time app starts monitoring during the same schedule
I've downloaded another screen time app that uses DeviceActivityMonitor, and once that app starts monitoring during an active monitoring schedule on my app - my app's monitoring schedule immediately ends. Is this expected behavior? Can't find this in any of the docs, but are two separate apps allowed to monitor activities during an overlapping schedule?
1
0
854
Feb ’23
Reply to How to run Timer into the ShieldActionExtension to wait user for 5 second to unlock the app?
ShieldActionExtensions will exit shortly after the completionHandler is called, so the Timer's closure will likely not be run before your extension's lifecycle ends. A better option would be to use a DeviceActivityMonitor extension. When the secondary button gets pressed, your ShieldActionExtension can create a DeviceActivitySchedule that starts 5 seconds from Date.now and start monitoring that schedule using a DeviceActivityCenter. Your DeviceActivityMonitor extension can then call Restrictions.shared.unlockAllApps() when it receives the intervalDidStart callback for that schedule.
Topic: App & System Services SubTopic: General Tags:
Feb ’23
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
Making Network Requests from DeviceActivityMonitor Extension
I am having a lot of trouble reliably making network requests from the DeviceActivityMonitor extension. In the app extension, when intervalDidEnd is called by the system, I add some data to the app's local CoreData store and sync that with the server. I use URLSession dataTask to make a POST request to my server, with URLSessionConfiguration.sharedContainerIdentifier set to my App Group's shared identifier. It is extremely rare that my server receives this request, although sometimes (rarely) it does. I've tried things like wrapping the task in performExpiringActivity or using URLSessionConfiguration.background suspecting that this task needs to run in the background, but none of it seems to work. What I suspect is happening is that the App Extension gets cancelled before the request is able to be invoked. Looking at the console logs, sometimes the work stops before the request is called, sometimes during the request task, and sometimes even before I am able to update my local data store. It's been v
2
0
1.1k
Feb ’23
How to trigger intervalDidStart in DeviceActivity API?
I have followed the two videos about Screen time API in wwdc 21 and 22. Now i want to sheild some apps during sleeping, but I encounter some problems. Problem I faced I write my monitor and override intervalDidStart and intervalDidEnd . Here is a simplified version class Mymonitor: DeviceActivityMonitor { let store = ManagedSettingsStore() override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) store.shield.applications = selection.applicationToken } then I use deviceActivityCenter to start monitor func StartSleep (_ startTime : DateComponents) { let schedule = DeviceActivitySchedule(intervalStart: startTime, intervalEnd: DateComponents(hour: 4, minute: 0), repeats: true ) let center = DeviceActivityCenter() center.stopMonitoring([.daily]) try! center.startMonitoring(.daily, during: schedule) } However, when I use StartSleep. The applications is not shielded. I have noticed that I haven't use Mymonitor in any place. In the demo Code, it seems i just ne
2
0
1.2k
Feb ’23
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
DeviceActivityMonitor Extension methods not being triggered
I did a lot of researches, but cannot understand why methods inside DeviceActivityMonitor extension are not calling. What I've seen related to this question and already checked: Do you starting monitoring for schedules? Yes, I do by calling center.startMonitoring() as it has been explained on WWDC2021-10123. I was searching an issue while creating the extension. Walk through steps that are described here. Everything looks good for me. Did you add Family Control Capability to extension's target? Yes, I did. Is your device authorized with FamilyControls? Yes. The only doubt I have here that I'm authorising FamilyControls for .individual . But as I've asked previously, it shouldn’t be a reason. Task { do { guard #available(iOS 16.0, *) else { // Fallback on earlier versions return } try await AuthorizationCenter.shared.requestAuthorization(for: .individual) switch AuthorizationCenter.shared.authorizationStatus { case .notDetermined: print(not determined) case .denied: print(denied) case .approved: print
10
0
2.5k
Feb ’23
ManagedSettingsStore is empty in DeviceActivityMonitor
I'm following the video with explanation of how to dealing with DeviceActivityMonitor extension. I'm facing the issue with empty ManagedSettingsStore when I'm trying to retrieve discouraged apps. The apps successfully where blocked on the selection step via .familyActivityPicker. The problem is that I can’t retrieve discouraged apps. I read that Model.shared won’t work in extension. To sync an app and extension we need to use AppGroups. Do we need to use AppGroups if we follow code like in the video?
3
0
1k
Jan ’23
Issues in rendering DeviceActivityController
Hey y'all, I've been staring at this so long that I think I might be going insane. So for Device activity , I can get the permissions to access, and I can even lock apps. But I can't get anything to print in the functions of my class with the override functions for DeviceActivityMonitor, and 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. Can someone please lend me a hand? I have seen at least three other people asking about something like this here and stack overflow and there are no answers. I have already included and am using app groups. I have already filed a bug report with feedback assistant. Thank you! I will try and update this in the morning.
2
0
803
Jan ’23
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
Screen Time discrepancy between DeviceActivityMonitor and DeviceActivityReport
My app monitors DeviceActivityEvents with no categories, apps, or websites selected because we want to monitor their time spent on all categories, apps, and websites. This is because my app gives users rewards for keeping their total Screen Time low. Unfortunately, it has been seemingly impossible to align the Screen Time shown with DeviceActivityReport to the Screen Time monitored with DeviceActivityMonitor. By default, the DeviceActivityReport captures more Screen Time than the DeviceActivityMonitor by default. But if I try to filter the report by totalActivityDuration on each category, it misses some Screen Time captured by the monitor (like FaceTime, for instance). I simply want to report to the user exactly the Screen Time I am monitoring by default with DeviceActivityMonitor. Is that possible without selecting any categories, apps, or websites in the monitor?
2
0
1.2k
Dec ’22
DeviceActivityMonitor - intervalDidStart() not able to restrict apps/categories/webCategories
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
8
0
3k
Dec ’22
Reply to Module 'DeviceActivity' not found
As Quinn suggested, you can add another layer of wrapping around your MyMonitor class. However, I don't see why you would need to use a DeviceActivityMonitor subclass in Objective-C code. The superclass is intended to be subclassed and used only in the context of your Device Activity monitor extension as the extension's principal class.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’22
Reply to Module 'DeviceActivity' not found
The issue here is that, in most languages, including Objective-C, a class’s super class is part of the class’s public API. In your example the MyMonitor class has a public use of DeviceActivityMonitor, which means that Swift has to include the framework that exports that class, DeviceActivity, in the generated MyTestProject-Swift.h header. However, DeviceActivity is a Swift-only framework, and so everything falls apart. One way around this is to add another layer of wrapping: import Foundation import DeviceActivity @objc(ObjCMonitor) class ObjCMonitor: NSObject { override init() { self.sm = SwiftMonitor() } private let sm: SwiftMonitor } private class SwiftMonitor: DeviceActivityMonitor { } Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’22
Reply to Module 'DeviceActivity' not found
I was also able to reproduce this by creating a new barebones project, with adding only two files: MyObjectiveC.m #import MyTestProject-Swift.h and MySwift.swift import DeviceActivity import ManagedSettings import Foundation @objc(MyMonitor) class MyMonitor: DeviceActivityMonitor { }
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’22