I want to block or shield the application which is selected by the user for specific time like 1 min..
this can be done by DeviceActivityMonitorExtension ? if no then please suggest how can I do that..!
I’ve tried this code, can anyone tell me it’s working or not? because I can’t run it on my phone because of some error (May be developer certificate error, I guess) but I can run it on virtual device but can’t see any app list there to select !
import DeviceActivity
import FamilyControls
import ManagedSettings
import SwiftUI
extension DeviceActivityName {
static let daily = Self("Daily")
}
extension DeviceActivityEvent.Name {
static let encoraged = Self("Encoraged")
}
let schedule = DeviceActivitySchedule (
intervalStart: DateComponents(hour: 0, minute: 0),
intervalEnd: DateComponents(hour: 1, minute: 01),
repeats: true
)
let center = DeviceActivityCenter()
let startMonitor: ()? = try? center.startMonitoring(.daily, during: schedule)
let model = FocusMode().model
let event: \[DeviceActivityEvent.Name: DeviceActivityEvent\] = \[.encoraged: DeviceActivityEvent(applications: model.applicationTokens, threshold: DateComponents(minute: 1))\]
// Optionally override any of the functions below.
// Make sure that your class name matches the NSExtensionPrincipalClass in your Info.plist.
class DeviceActivityMonitorExtension: DeviceActivityMonitor {
let store = ManagedSettingsStore()
override func intervalDidStart(for activity: DeviceActivityName) {
super.intervalDidStart(for: activity)
print("Device Activity Is Running..!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
let model = FocusMode().model
let apps = model.applicationTokens
store.shield.applications = apps.isEmpty ? nil : apps
store.shield.applications = apps.isEmpty ? nil : apps
// Handle the start of the interval.
}
override func intervalDidEnd(for activity: DeviceActivityName) {
super.intervalDidEnd(for: activity)
super.intervalDidEnd (for: activity)
store.shield.applications = nil
// Handle the end of the interval.
}
override func eventDidReachThreshold(_ event: DeviceActivityEvent.Name, activity: DeviceActivityName) {
super.eventDidReachThreshold(event, activity: activity)
store.shield.applications = nil
}
}
I can’t test it can anyone tell me this is right of wrong, if wrong then suggest me how to do it ?




