Search results for

“DeviceActivityMonitor”

143 results found

Post

Replies

Boosts

Views

Activity

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 How does child can unblock apps for some period of time using Screen Time API?
what your code actually says is: after 30 seconds of total usage of the application that you selected (applications.applicationTokens) the eventDidReachThreshold of the DeviceActivityMonitor extension will be called. handle your event .encouraged inside the eventDidReachThreshold and do there what ever you like. i think for you case if you want to limit some apps for a period of time just make a scheduled event that start from the current time you tapped an OK button (or some other action) to current time + limitation time of tour choice. and on your DeviceActivityMonitor extension you should handle the blocking and unblocking on the intervalDidStart and intervalDidEnd the your code should look something like this: do { let schedule = DeviceActivitySchedule(intervalStart: start, intervalEnd: end, repeats: false, warningTime: nil) try center.startMonitoring(.block, during: schedule) } catch { print(error: + error.localizedDescription) }
Topic: App & System Services SubTopic: General Tags:
Jan ’22
DeviceActivityMonitor eventDidReachThreshold triggering every time in same second as intervalDidStart gets called
Hello, I am trying to make use of Screentime API in my app, I have issue with the DeviceActivityMonitor extension. I have schedule DeviceActivitySchedule which I set like this: let schedule = DeviceActivitySchedule( intervalStart: DateComponents(hour: 00, minute: 00), intervalEnd: DateComponents(hour: 23, minute: 59), repeats: false ) and DeviceActivityEvent which I set like this: let dateComponent = DateComponents(minute: 1) var events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [ .encouraged: DeviceActivityEvent(threshold: dateComponent) ] The issue is that every time I start monitoring, by calling this piece of code from the app: do { print(Try start monitoring...) try center.startMonitoring(.daily, during: schedule, events: events) } catch { print(Error: , error) } I catch in the extension that the event intervalDidStart is called, but in the same second I get called eventDidReachThreshold. What could be done wrong? Is event set properly? I was trying to set event with different Datecompon
3
0
1.7k
Apr ’23
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 DeviceActivityMonitor - Callbacks not trigger
Hi, I've faced a unexpected behavior in my screen time app (AppStops) when using structured concurrency tools in non-isolated DeviceActivityMonitor class. This changes may solve your problems. Remove @MainActor from AppUsageManager Remove Task from your codes. I recommend you to use non-isolated types and methods for DeviceActivityCenter. I hope this helps.
Topic: App & System Services SubTopic: General Tags:
Jan ’25
Reply to Interact with ManagedSettingsStore from DeviceActivityMonitor
Starting in iOS 16, ManagedSettingsStores will share the same settings in the DeviceActivityMonitor extension as the host application. Meaning if you set a setting (like shield.applications) in ManagedSettingsStore() in the app, you will see the same setting in ManagedSettingsStore() in the extension. So, for example this will shield apps in the host application, and clear those same shields once the activity ends. App: func shieldApplications() { let selections = FamilyActivitySelection(includeEntireCategory: true) /* Get Application Tokens from FamilyActivityPicker */ let store = ManagedSettingsStore() store.shield.applications = selections.applicationTokens } Extension: class MyDeviceActivityMonitor: DeviceActivityMonitor { let store = ManagedSettingsStore() public override func intervalDidEnd(for activity: DeviceActivityName) { super.intervalDidEnd(for: activity) store.shield.applications = nil } } If you do not want this behavior, please use the ManagedSettingsStore(named:) initializer
Topic: App & System Services SubTopic: General Tags:
Mar ’23
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
432
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 Sending screentime data to firebase then to accountability partner
So i tried a different solution . It works 80% of the time but sometimes the value lags and idk why . I used deviceactivitymonitor extension to set thresholds every 30mins so when user's screentime reaches a certain value it fires.... so there's no saving or manipulating data . on the accountability partner's end they see 0.5hr+, 1.0hr+, 1.5hr+ etc . it updates only when the user crosses a registered threshold. Problem is sometimes it takes a while to fire ... it could lag for about an hour . eg if user screentime is 2hr43min it's still stuck on 1.5hr+ when it's supposed to be 2.5hrs+ . I don't know why this happens. Any ideas?
Topic: App & System Services SubTopic: General Tags:
2w
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
DeviceActivityMonitor intervalDidStart does not fire automatically at scheduled time — blocking only works when user opens the app
I have Family Controls (Distribution) and (Development) on my main app. The shield overlay, shield actions, and ManagedSettingsStore all work correctly. My app concept: the user selects a specific time (e.g. 7:00 AM) at which their selected apps (Instagram, TikTok, Snapchat, etc.) should be blocked until they complete an action. The blocking should happen everyday automatically at the chosen time without the user needing to open my app. What actually happens: at 7:00 AM nothing happens. The selected apps remain accessible. The blocking only activates when the user manually opens my app and then closes it. Has anyone found a reliable way to make intervalDidStart fire every day at the scheduled time in the background? Is there a known workaround? I have seen similar reports from other developers but no confirmed solution. Any guidance from Apple engineers would be greatly appreciated.
0
0
85
2w
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 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:
Replies
Boosts
Views
Activity
Dec ’22
Reply to How does child can unblock apps for some period of time using Screen Time API?
what your code actually says is: after 30 seconds of total usage of the application that you selected (applications.applicationTokens) the eventDidReachThreshold of the DeviceActivityMonitor extension will be called. handle your event .encouraged inside the eventDidReachThreshold and do there what ever you like. i think for you case if you want to limit some apps for a period of time just make a scheduled event that start from the current time you tapped an OK button (or some other action) to current time + limitation time of tour choice. and on your DeviceActivityMonitor extension you should handle the blocking and unblocking on the intervalDidStart and intervalDidEnd the your code should look something like this: do { let schedule = DeviceActivitySchedule(intervalStart: start, intervalEnd: end, repeats: false, warningTime: nil) try center.startMonitoring(.block, during: schedule) } catch { print(error: + error.localizedDescription) }
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jan ’22
DeviceActivityMonitor eventDidReachThreshold triggering every time in same second as intervalDidStart gets called
Hello, I am trying to make use of Screentime API in my app, I have issue with the DeviceActivityMonitor extension. I have schedule DeviceActivitySchedule which I set like this: let schedule = DeviceActivitySchedule( intervalStart: DateComponents(hour: 00, minute: 00), intervalEnd: DateComponents(hour: 23, minute: 59), repeats: false ) and DeviceActivityEvent which I set like this: let dateComponent = DateComponents(minute: 1) var events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [ .encouraged: DeviceActivityEvent(threshold: dateComponent) ] The issue is that every time I start monitoring, by calling this piece of code from the app: do { print(Try start monitoring...) try center.startMonitoring(.daily, during: schedule, events: events) } catch { print(Error: , error) } I catch in the extension that the event intervalDidStart is called, but in the same second I get called eventDidReachThreshold. What could be done wrong? Is event set properly? I was trying to set event with different Datecompon
Replies
3
Boosts
0
Views
1.7k
Activity
Apr ’23
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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Dec ’22
Reply to DeviceActivityMonitor - Callbacks not trigger
Hi, I've faced a unexpected behavior in my screen time app (AppStops) when using structured concurrency tools in non-isolated DeviceActivityMonitor class. This changes may solve your problems. Remove @MainActor from AppUsageManager Remove Task from your codes. I recommend you to use non-isolated types and methods for DeviceActivityCenter. I hope this helps.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jan ’25
Reply to Interact with ManagedSettingsStore from DeviceActivityMonitor
Starting in iOS 16, ManagedSettingsStores will share the same settings in the DeviceActivityMonitor extension as the host application. Meaning if you set a setting (like shield.applications) in ManagedSettingsStore() in the app, you will see the same setting in ManagedSettingsStore() in the extension. So, for example this will shield apps in the host application, and clear those same shields once the activity ends. App: func shieldApplications() { let selections = FamilyActivitySelection(includeEntireCategory: true) /* Get Application Tokens from FamilyActivityPicker */ let store = ManagedSettingsStore() store.shield.applications = selections.applicationTokens } Extension: class MyDeviceActivityMonitor: DeviceActivityMonitor { let store = ManagedSettingsStore() public override func intervalDidEnd(for activity: DeviceActivityName) { super.intervalDidEnd(for: activity) store.shield.applications = nil } } If you do not want this behavior, please use the ManagedSettingsStore(named:) initializer
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Mar ’23
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?
Replies
0
Boosts
0
Views
432
Activity
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.
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Sending screentime data to firebase then to accountability partner
So i tried a different solution . It works 80% of the time but sometimes the value lags and idk why . I used deviceactivitymonitor extension to set thresholds every 30mins so when user's screentime reaches a certain value it fires.... so there's no saving or manipulating data . on the accountability partner's end they see 0.5hr+, 1.0hr+, 1.5hr+ etc . it updates only when the user crosses a registered threshold. Problem is sometimes it takes a while to fire ... it could lag for about an hour . eg if user screentime is 2hr43min it's still stuck on 1.5hr+ when it's supposed to be 2.5hrs+ . I don't know why this happens. Any ideas?
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
2w
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:
Replies
Boosts
Views
Activity
Feb ’23
DeviceActivityMonitor intervalDidStart does not fire automatically at scheduled time — blocking only works when user opens the app
I have Family Controls (Distribution) and (Development) on my main app. The shield overlay, shield actions, and ManagedSettingsStore all work correctly. My app concept: the user selects a specific time (e.g. 7:00 AM) at which their selected apps (Instagram, TikTok, Snapchat, etc.) should be blocked until they complete an action. The blocking should happen everyday automatically at the chosen time without the user needing to open my app. What actually happens: at 7:00 AM nothing happens. The selected apps remain accessible. The blocking only activates when the user manually opens my app and then closes it. Has anyone found a reliable way to make intervalDidStart fire every day at the scheduled time in the background? Is there a known workaround? I have seen similar reports from other developers but no confirmed solution. Any guidance from Apple engineers would be greatly appreciated.
Replies
0
Boosts
0
Views
85
Activity
2w
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:
Replies
Boosts
Views
Activity
May ’22