Search results for

DeviceActivityMonitor

127 results found

Post

Replies

Boosts

Views

Activity

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
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
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 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
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
Feb ’23
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
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 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
Module 'DeviceActivity' not found
I have a class that uses DeviceActivityMonitor as a subclass: // MyMonitor.swift import DeviceActivity @objc(MyMonitor) class MyMonitor: DeviceActivityMonitor { ... } In order to use SwiftUI in Objective-C, I'm importing this in my objective-c file #import MyProject-Swift.h. But, when I try to build, I get the error Module 'DeviceActivity' not found from wthin #import MyProject-Swift.h I've tried Link Binary with Libraries: I've also tried to turn on Define Modules in Build Settings -> Packaging. It just seems as though the DeviceActivity framework doesn't have a header file. Seems like it should? When I click Show in Finder in MyProject -> Frameworks -> DeviceAcitivity.framework, there is not DeviceActivity.h file in that dir (also not in the modules folder in my screenshot): Is there a way to create a header file for an apple framework? Or force the creation of one? I have also tried cleaning the build folder Here's the framework for reference: https://developer.apple.com/document
6
0
1.7k
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
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
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
ScreenTime API
Can the Screen Time API in iOS be used to block specific applications or application categories from getting launched? I went through the documentation here: https://developer.apple.com/videos/play/wwdc2022/110336/ and it indicates that we should be able to block certain app categories using the DeviceActivity and FamilyControl Framework. So, I created the following code snippet: class DeviceActivityMonitorExtension: DeviceActivityMonitor { let store = ManagedSettingsStore() override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) NSLog(interval did start) let model = MyModel.shared let applications = model.selectionToDiscourage.applicationTokens store.shield.applications = applications.isEmpty ? nil : applications store.dateAndTime.requireAutomaticDateAndTime = true } And made a class model var selectionToDiscourage = FamilyActivitySelection() { willSet { NSLog (got here (newValue)) let applications = newValue.applicationTokens let categories = newValu
2
0
3.1k
Sep ’22